Submit | All submissions | Best solutions | Back to list |
EZDIJKST - Easy Dijkstra Problem |
Determine the shortest path between the specified vertices in the graph given in the input data.
Hint: You can use Dijkstra's algorithm.
Hint 2: if you're a lazy C++ programmer, you can use set and cin/cout (with sync_with_stdio(0)) - it should suffice.
Input
first line - one integer - number of test cases
For each test case the numbers V, K (number of vertices, number of edges) are given.
Then K lines follow, each containing the following numbers separated by a single space:
ai, bi, ci
It means that the graph being described contains an edge from ai to bi, with a weight of ci.
Below the graph description a line containing a pair of integers A, B is present.
The goal is to find the shortest path from vertex A to vertex B.
All numbers in the input data are integers in the range 0..10000.
Output
For each test case your program should output (in a separate line) a single number C - the length of the shortest path from vertex A to vertex B. In case there is no such path, your program should output a single word "NO" (without quotes)
Example
Input: 3 3 2 1 2 5 2 3 7 1 3 3 3 1 2 4 1 3 7 2 3 1 1 3 3 1 1 2 4 1 3 Output: 12 5 NO
Added by: | Robert Rychcicki |
Date: | 2009-01-10 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS OBJC PERL6 VB.NET |
hide comments
|
||||||||||||
2015-10-13 18:16:34 Nguyen Tung
Directed graph and the number of verticles might exceed 1000. I got 2 SIGSEGV runtime errors while trying with maximum verticles = 200 and 500. Got AC with 10000. |
||||||||||||
2015-07-27 05:03:33 harshit sharma
question should be more clear.. |
||||||||||||
2015-07-23 00:08:42 Rajat (1307086)
Direct problem. |
||||||||||||
2015-06-29 19:50:01 Aman Agarwal
weak test cases :( |
||||||||||||
2015-06-29 13:05:53 SANDEEP KUMAR
My god,was using scanf inside io_base::sync_with_stdio(FALSE),got 7 SIGSEV's and finally AC in 0.00s :) |
||||||||||||
2015-06-10 22:24:02 Shubham
thanks to STL in c++...:) |
||||||||||||
2015-05-25 16:19:35 RAHUL
my god this is directed |
||||||||||||
2015-01-31 07:24:03 lovecode
i was taking undirected graph this cause me 1 WA......PROBLEM SETTER plz mention this in question |
||||||||||||
2015-01-06 15:20:16 Shaurya Chaturvedi
Thanks @tranquil, got WA: I used undirected. :P |
||||||||||||
2014-11-28 06:00:03 yagyank
Breaking on loop from target node does not cost wa :) |