Given a graph consisting ‘N’ nodes (labeled 1 to N) where a specific given node ‘S’ represents the starting position and an edge between two nodes is of a given length, which may or may not be equal to other lengths in the graph.
It is required to calculate the shortest distance from the start position (Node ‘S’) to all of the other nodes in the graph.
If a node is unreachable, the distance is assumed as -1.
Input Format
The first line contains T, denoting the number of test cases. First line of each test case has two integers N, M denoting the number of nodes in the graph and, denoting the number of edges in the graph.
The next M lines each consist of three space-separated integers x,y,r where x and y denote the two nodes between which the undirected edge exists, ‘r’ denotes the length of edge between these corresponding nodes.
The last line has an integer, ‘S’ denoting the starting position.
Constraints
1 <= N <= 3000 1 <= M <= (N*(N-1))/2 1 <= x,y <= N 1 <= r <= 10^5
Output Format
For each of the T test cases, print a single line consisting N-1 space separated integers denoting the shortest distance of N-1 nodes other than from starting position S in increasing order of their labels.
For unreachable nodes, print -1.
My code for the above problem is giving segmentation fault:https://ide.codingblocks.com/s/269356