Depth First Search - Timestamps#8761

Depth First Search - Timestamps

1 second
128 megabytes
Medium

An undirected graph is given. Vertices are numbered from . Run depth first search from the given vertex . Print the timestamps d_v and f_v for each vertex in increasing order of vertices.

Input

The first line contains the number of vertices n~(n \le 100) and the number of edges of the undirected graph. Each of the next lines contains two vertices and , denoting an undirected edge of the graph. The last line contains the starting vertex .

Output

Run . Print the timestamps d_v and f_v for each vertex v~(v = 1, 2, ..., n). The timestamps for each vertex must be printed in a separate line, in the order of increasing vertex number.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading