Depth First Traversal

0

0 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. Calculate the Depth First order of nodes considering node s as source node.

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 Depth first order of traversal of nodes.

Constraints:

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

Sample Input
5 4
1 2
2 3
2 4
3 5
2
Sample Output
2 1 3 5 4 
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?