Advertisement
Guest User

b

a guest
Oct 6th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1.  
  2. Road Decoration
  3. Add problem to Todo list
  4. Problem code: AMR14B
  5.  
  6.  
  7. SUBMITMY SUBMISSIONSALL SUBMISSIONS
  8. Australia and New Zealand have started working on preparation for the World Cup 2015. There are N important venues (like hotels and stadiums) in the city. Out of these important venues, there is one central location where the opening and closing ceremony will be held. There is an existing network of bidirectional roads connecting these venues. The organizing committee has planned to decorate some of these roads that will be used for commuting. They have decided to choose the roads to decorate such that there is exactly one decorated path to all the venues from the central location.
  9. New Zealand is supposed to decorate these roads and Australia has taken up the responsibility of providing transportation. Only decorated roads can be used for transportation. Australia wanted to save fuel costs, and so they wanted to choose the decorated roads to minimize the total sum of distances to all venues from the central location. However, New Zealand had their own plans to minimize decoration cost by choosing the decorated roads such that the sum of the length of the chosen roads will be minimized.
  10. To prevent a fight breaking out between these two rivals before they even step on to the field, you have to help them by reporting if there is a solution in which the two rivals could choose the same set of roads while satisfying their respective constraints.
  11. Input:
  12. The first line contains the number of test cases T.
  13. For each test first line contains N and M which are number of venues and total number of roads respectively.
  14. Then next M lines for each case contains u, v and w - indicating that there is a bidirectional road of distance w between locations u and v.
  15. The central location is identified with location 0.
  16. Output:
  17. For each test case, output the required answer on a separate line. If there is a valid plan, then print “YES”. Else, print “NO” (quotes for clarity).
  18. Note: If any of the venues is not reachable from the central location, then print “NO”.
  19. Constraints:
  20. 1 <= T <= 10000
  21. 1 <= N <= 20000
  22. 0 <= M <= 40000
  23. 0 <= u < N
  24. 0 <= v < N
  25. u != v
  26. 1 <= w <= 10^9
  27. The sum of values of N over all test cases will not be more than 1000000.
  28. The sum of values of M over all test cases will not be more than 2000000.
  29.  
  30. Example:
  31. Sample Input:
  32. 3
  33. 3 3
  34. 0 1 1
  35. 0 2 2
  36. 1 2 2
  37. 3 1
  38. 0 1 1
  39. 4 5
  40. 2 1 9
  41. 3 2 5
  42. 0 3 9
  43. 0 1 2
  44. 3 1 9
  45.  
  46. Sample Output:
  47. YES
  48. NO
  49. NO
  50.  
  51. Explanation:
  52. For the first case, both of them can choose the roads {0<-->1, 0<-->2}.
  53. For the second case, venue 2 is not reachable from the central location 0.
  54.  
  55. Author: murdocc007
  56. Date Added: 27-12-2014
  57. Time Limit: 6 sec
  58. Source Limit: 50000 Bytes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement