Programming contests

DEIK Regionális Programozó Csapatverseny, nyílt kategória, 2017. december 3.

December 3, 2017 10:10 AM – December 3, 2017 3:10 PM

K — Hiking

Lea enjoys nature a lot, therefore she often goes hiking at the weekend. Last Sunday, she got up early, drove to the foot of a mountain and reached the top just at the right time for lunch. During her dessert, “Apfelstrudel”, she suddenly remembered: she had a very important appointment this afternoon which she was about to miss. In a big hurry, she looked at the map to figure out the fastest way to her car. To her amazement, there were hundreds of walking tracks which crossed multiple times forming thousands of possible routes down! Lea was helpless. Luckily she had her satellite phone with her and called… you! After giving you the list of all the tracks, she wants to know how far away from her car she currently is. Help her out!

Input Specification

The first line of the input contains an integer t (1 ≤ t ≤ 20). t test cases follow. Two consecutive test cases are separated by a blank line.

Each test case starts with two integers n and m (1 ≤ n ≤ 1000, 1 ≤ m ≤ 50000), where n is the number of intersections, those are numbered from 1 to n, and m is the number of walking trails. Then m lines follow. The ith line contains three integers vi, wi, and ci (1 ≤ viwi ≤ n, 1 ≤ ci ≤ 1000). vi and wi each denote an intersection of walking trails, ci is the length of a walking track connecting those intersections. Walking trails are undirected. Lea is currently at intersection 1, her car is at intersection n.

Output Specification

For each test case, output one line containing “Case #id” where i is its number, starting at 1, and d is the shortest distance from intersection 1 to intersection n. Each line of the output should end with a line break.

Sample Input 1

  1. 4
  2. 3 2
  3. 1 2 1
  4. 2 3 2
  5. 3 3
  6. 1 2 1
  7. 1 3 3
  8. 2 3 1
  9. 3 2
  10. 1 2 1
  11. 2 3 2
  12. 3 2
  13. 1 3 5
  14. 2 3 4
download as text file

Output for Sample Input 1

  1. Case #1: 3
  2. Case #2: 2
  3. Case #3: 3
  4. Case #4: 5
download as text file

Sample Input 2

  1. 7
  2. 4 4
  3. 1 3 2
  4. 1 4 2
  5. 2 4 5
  6. 3 4 3
  7. 5 4
  8. 1 3 2
  9. 1 4 1
  10. 2 5 5
  11. 3 2 4
  12. 5 5
  13. 1 3 2
  14. 1 5 2
  15. 2 4 5
  16. 2 5 2
  17. 4 5 2
  18. 3 2
  19. 1 2 1
  20. 2 3 5
  21. 2 1
  22. 1 2 3
  23. 4 4
  24. 1 2 3
  25. 2 4 4
  26. 1 4 1
  27. 3 4 2
  28. 5 6
  29. 1 2 2
  30. 1 4 5
  31. 3 4 2
  32. 2 4 1
  33. 2 3 1
  34. 4 5 5
download as text file

Output for Sample Input 2

  1. Case #1: 2
  2. Case #2: 11
  3. Case #3: 2
  4. Case #4: 6
  5. Case #5: 3
  6. Case #6: 1
  7. Case #7: 8
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019