Depth-First Search on a Disconnected Graph#9654

Depth-First Search on a Disconnected Graph

1 second
128 megabytes
Medium

An undirected disconnected graph is given. Perform a depth-first search on it. For each vertex output the timestamps when it becomes gray / black in the order of their first visit.

Input

The first line contains the number of vertices (n \le 100) of the undirected graph. Each of the following lines contains two vertices and - an undirected edge of the graph.

Output

Perform a depth-first search on the graph. For each vertex in a separate line, output the timestamps when it becomes gray / black in the order of their first visit. Vertices should be traversed in order of increasing numbers.

prb9654.gif

Examples

Example 1

Loading
Loading