Skip to content
C

DFS Traversal

Easyjavapythonccppjavascript

Given an undirected graph and a starting vertex S, visit all reachable vertices using Depth-First Search. When a vertex is expanded, visit its neighbours in increasing order.

Input Format

The first line contains two integers V and E. Each of the next E lines contains an undirected edge u v. The last line contains the starting vertex S.

Output Format

Print the DFS visit order (only reachable vertices), separated by single spaces.

Input (stdin)

Output

Run your code to see output here...