Linkedin OA
Anonymous User
405

You have just arrived in a new city and would like to see its sights. Each sight is located in a square and you have assigned each a beauty value. Each road to a square takes an amount of time to travel, and you have limited time for sightseeing. Determine the maximum value of beauty that you can visit during your time in the city. Start and finish at your hotel, the location of sight zero.

Example:
n=4 (number of squares)
m = 3 (number of bidirectional roads)
max_time = 50
beauty= (5, 10, 15, 20)
road_from = (0, 1, 0)
road_to = (1, 2, 3)
road_time = (10, 10, 10)

Output:
30

To visit square 0, 1 and 2 (starting and ending at 0), time taken is 10 + 10 + 10 + 10 = 40 minutes and it has 5 + 10 + 15 = 30 beauty value (the beauty value is only counted on the fist visit).

Constraints:
1 <= n<= 1000
1 <= m <=2000
10 <= max_time <= 100
u[i] != v[i]
10 <= t[i] <= 100
No more than 4 roads connect a single square with others.
Two squares can be connected by at most one road.

Can you please help to solve this? The problem is easy to do for a tree, but I am not sure how to solve this when the graph is not a tree.

Comments (3)