You are given a weighted undirected graph with n vertices and m edges. Find the shortest distance from a source vertex s to every vertex.
If a vertex is unreachable, its distance is -1.
The first line contains n, m and s.
The next m lines each contain u, v and w: an edge between u and v with non-negative weight w.
Vertices are numbered from 1 to n.
Print n integers on one line: the distance from s to vertex 1, vertex 2, ..., vertex .
Write your solution, test it against custom input, then submit for a real verdict.
Your submissions, verdicts, drafts and contest score are tied to your account. Registration is free.
n1 <= n <= 100000
0 <= m <= 200000
0 <= w <= 10^9
The graph may be disconnected and may contain multiple edges.
4 4 1 1 2 4 1 3 1 3 2 2 2 4 1
0 3 1 4