BFS - Shortest Path
https://hack.codingblocks.com/app/contests/c/969/p/763
i dint understand input and output format of this problem ? explain it
BFS - Shortest Path
https://hack.codingblocks.com/app/contests/c/969/p/763
i dint understand input and output format of this problem ? explain it
2 // this represent no of queries means no of times you have to give output
4 2 // 4 is total no of nodes but edges are only 2
1 2 // these are edges
1 3 // these are edges
1 // this is starting node from where you have to apply BFS
output of this query : 6 6 -1
distance of 2 from 1: 6
distance of 3 from 1: 6
distance of 4 from 1: -1 because not connected
3 1 //3 is total no of nodes but edges are only 1
2 3 // this is edge
2 // starting node is 2
output of this query : -1 6
distance of 1 from 2: -1
distance of 3 from 2: 6
i hope now you understand it if yes then hit a like
@Saurabh2 sir in question distance between two connected node is not mention so why you multiplied distance between two node by 6
???
see question carefully it is mention
question
Consider an undirected graph consisting of ānā nodes where each node is labeled from 1 to n and the edge between any two nodes is always of length 6 . We define node āsā to be the starting position for a BFS.
Given āqā queries in the form of a graph and some starting node, āsā , perform each query by calculating the shortest distance from starting node āsā to all the other nodes in the graph. Then print a single line of n-1 space-separated integers listing node sās shortest distance to each of the n-1 other nodes (ordered sequentially by node number); if āsā is disconnected from a node, print -1 as the distance to that node.