EZDIJKST - Easy Dijkstra Problem

no tags 

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.


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.


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)


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


hide comments
schnaggrwl: 2020-08-10 08:50:03

directed graph!

yashkwatra92: 2020-07-31 16:58:58

done in second attempt so much easy though

cynder: 2020-07-09 21:56:05

AC in 7th go :)
Ez prob
I recommend

hchauhan7816: 2020-04-27 17:04:58

For information, the graph has directed edges. Be careful !!

rahatkhan99: 2020-04-04 13:38:25

WTF is going here??? You should give a hint if it's a directed or undirected graph.

mahatejvarma: 2020-03-22 15:41:42

First time commenting this...AC in one go!!!

deependra_18: 2020-03-15 15:07:41

graph is directed so be careful it cost me 1 WA.

hamobos_499: 2019-12-12 15:33:42

The graph is directed btw

gabirosa: 2019-12-03 02:54:36

tenso migos

hetp111: 2019-09-02 13:48:50

memset doesnt work for big value.... use fill() instead or a loop.

Last edit: 2019-09-02 13:50:56

Added by:Robert Rychcicki
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)