Dijkstra Shortest Path (Many Cases)

Programming Interview Hard 5 views
Back to Questions

Problem Description

For each testcase you get weighted undirected graph. Output shortest distance from 1 to n. If unreachable output -1.

Input Format

First integer t. For each: n m then m lines u v w.

Output Format

t lines distances.

Sample Test Case

Input:
1 5 6 1 2 2 1 3 4 2 3 1 2 4 7 3 5 3 4 5 1
Output:
6

Constraints

Sum of n+m over all testcases

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next