Блог пользователя NeverSayNever

Автор NeverSayNever, 11 лет назад, По-английски

Hello Fellas ,

I am trying to solve this problem from Quora Hackathon but not able to come up with a idea .. how to appraoch it ?

Can any one help ..

Just for the convenience i have copied the problem statement here otherwise you can use this link

Problem Statement

For the purposes of this problem, suppose Quora has N questions, and question i (1≤i≤N) takes Ti time to read. There exists exactly one path from any question to another, and related questions form undirected pairs between themselves. In other words, the graph of related questions is a tree.

Each time Steve reads a question, he will see a list of related questions and navigate to one that he hasn't read yet at random. Steve will stop reading once there are no unread related questions.

Which question should we show first to Steve so that we minimize his total expected reading time? It is guaranteed that there is one unique question that is optimal.

Input Format

Line 1: A single integer, N

Line 2: N integers, Ti

Line 3...N+1: Each line contains two integers A, B indicating that question A and B are

related

Output Format

Line 1: A single integer, X, the best question to show first.

Constraints

1≤N≤105

1≤Ti≤106

Sample Input

5

2 2 1 2 2

1 2

2 3

3 4

4 5

Sample Output

3

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This question was already asked few weeks ago, here is that post.

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I am unable to understand your approach . Can you be more clear .. Please

    As you said that this is standard DP problem there must be some more problems based on the similar comcept. So , can you provide links for those problems too .

    • »
      »
      »
      11 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Maybe my solution from a contest will help you — here it is. Sorry, it looks a bit messy, like almost all my solutions :) But I hope it will help you.

      Problem based on the similar concept — Long Drive from recent CodeChef contest. There are lot of possible ways to solve this one, but you can try similar DP on a tree. First of all for every vertex you can find length of longest path going down from this vertex in a single run of dfs. Then run another dfs to find longest path going up — it will be either path going to a parent and then up (and you should already have an answer for moving up from a parent) or path going to a parent and then down into one of subtees (and answers for this case you already got while solving moving down only part).

      In your problem from Hackathon we have to deal with a bit more complicated formulas for calculating probabilities, but general idea is same.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

By the way, has anyone received e-mail from hackerrank "Quora is interested in talking to you" after this hackathon?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Check my comment