Problems
Depth First Search - Timestamps
Depth First Search - Timestamps
Undirected graph is given. Run depth first search from the given vertex $v$. Print the timestamps $d[v]$ and $f[v]$ for each vertex $v$ in the increasing order of vertices.
\InputFile
The first line contains number of vertices $n~(n \le 100)$ and edges $m$ of undirected graph. Each of the next $m$ lines contains two vertices $a$ and $b$ --- an undirected edge of the graph. The last line contains vertex $v$.
\OutputFile
Run $dfs(v)$. 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.
\includegraphics{https://static.eolymp.com/content/89/8932cfa506232291c4dc772ca36e12860d40def5.gif}
Input example #1
3 3 1 2 2 3 1 3 2
Output example #1
2 5 1 6 3 4
Input example #2
5 5 1 2 2 3 2 5 2 4 1 4 3
Output example #2
3 6 2 9 1 10 4 5 7 8