Three Diameter with restrictions
Question:
Three Diameter with restrictions
Hi guys, I’m trying to solve the following problem:
Given a Tree Graph (undirected), where each edge has a value and a cost, find the biggest path between any two vertices that maximize the sum of the values and the sum of the costs can’t be more then a value C.
Constraints:
2 <= Number of Vertices <= 30.000
1 <= C <= 100000000
The value and cost of each edge is positive and less or equal then 1000
I know how to calculate the diameter of the three without the restrictions using two bfs, but can't continue the idea.
Answer:
You can solve this with two bfs ( i don’t unerstand ur post fully). first you run dfs from arbitrary node and calculate the cost of every node. The node having the highest cost will be on longest path. so your run dfs from that node and calculate the cost. return the maximum cost . currently i am not able to prove this but it works and i solved problem on spoj.pl using this approach. you just search on topcoder . i guess u will find lot more useful material.
Hope it is helpful for u .
Is It The Correct Answer?


