Shortest Distance from Source

4.5

2 votes
Easy
Problem

Given n, i.e. total number of nodes in an undirected graph numbered from 1 to n and an integer e, i.e. total number of edges in the graph. Find the shortest distance of all the node from the source node s.

Input Format:

First line of input line contains two integers n and e. Next e line will contain two integers u and v meaning that node u and node v are connected to each other in undirected fashion. Last line will contain an integer s denoting the source node.

Output Format:

For each input graph print the shortest distance of each node from the source node.

Constraints:

All the input values are well with in the integer range.

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?