Advertisement
Guest User

Hitchhiking

a guest
Mar 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. Start Date: 13/03/18 at 10:31AM UTC
  2.  
  3. Description: Alex is hitchiking in a country with N cities, connected by M bidirectional roads. She starts at city 1, and wants to get to city N. Furthermore, while most roads are safe, some are dangerous for hitchhikers. If Alex is always able to find a ride, this problem requires you to find the minimum number of dangerous roads that must be travelled along to get to city N, and the total number of roads travelled (while minimising the number of dangerous roads).
  4.  
  5. Your input should be called Hitch.java/rb/py
  6.  
  7. INPUT
  8.  
  9. The first line contains two integers representing the number of cities (N<10001) and number of roads (M<10001).
  10.  
  11. The following M lines contain three space separated integers each. Line i is of the form Ai Bi Ti which indicates a road between cities Ai and Bi. Ti is 1 if road i is dangerous, and 0 if it is safe.
  12.  
  13. OUTPUT
  14.  
  15. If Alex cannot reach city N, the output should be -1. Otherwise, the output should be two space-separated integers consisting of the minimum number of dangerous roads and the total number of roads, that Alex must travel along to reach her destination while minimising the number of dangerous roads she goes along.
  16.  
  17. SAMPLE INPUT 1
  18. 4 5
  19. 1 2 0
  20. 1 3 1
  21. 1 4 1
  22. 2 3 0
  23. 3 4 0
  24.  
  25. SAMPLE OUTPUT 1
  26. 0 3
  27.  
  28. EXPLANATION
  29. While Alex can travel from city 1 to city 4, this path goes along a dangerous road, which can be avoided by going from city 1 to 2, to 3 to 4.
  30.  
  31. SAMPLE INPUT 2
  32. 4 6
  33. 1 1 0
  34. 1 3 1
  35. 4 2 1
  36. 4 3 0
  37. 2 4 0
  38. 2 3 0
  39.  
  40. SAMPLE OUTPUT 2
  41. 1 2
  42. End Date: 22/03/18 at 11:59PM UTC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement