2
4 2
1 2
1 3
1
3 1
2 3
2
what these individual input representing
2
4 2
1 2
1 3
1
3 1
2 3
2
what these individual input representing
Here the first 2 in line 1 stands for number of test cases.
Then we start with the first testcase. 4 is the number of nodes and 2 is the number of edges.
After this in line 3 and 4 we have the edges of the graph.
And in line 5 we have ‘1’ as the source vertex ,i.e., the node from which we have to find the distance.
This marks the end of first testcase and is followed by a second test case.
In second testcase we have 3 nodes and 1 edge.
@chemant077 First mistake was that you need to insert a bidirectional edge not a single direction edge.
void add(int u,int v)
{
m[u].push_back(v);
m[v].push_back(u);
}
Second was the printing order because the order of values stored as adjacency list is not in ascending order , so I replaced the part where you are printing with a normal for loop
for(int node=1;node<=n;node++)
{
if(node==src) continue;
if(dis[node]==0)
cout<<-1<<" ";
else{
cout<<dis[node]*6<<" ";
}
}
This is the corrected code https://ide.codingblocks.com/s/215840 for reference.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.