Problems
Directed graph - timestamps
Directed graph - timestamps
The directed graph is given in the form of an adjacency list. Run a depth-first search on the graph. Print the timestamps $d[v]$ and $f[v]$ for each vertex $v$ in ascending order of vertices.
\InputFile
The first line contains the number of vertices $n~(1 \le n \le 100)$. The next $i$-th line contains the number of edges adjacent to the $i$-th vertex and the vertex numbers.
\OutputFile
Run a depth-first search on the graph. Print the timestamps $d[v]$ and $f[v]$ for each vertex $v~(v = 1, 2, ..., n)$. Print the timestamps for each vertex on a separate line.
\includegraphics{https://static.eolymp.com/content/03/03cbe715154255351b2f856007e11fefc142f16a.gif}
Input example #1
6 0 2 1 3 1 5 0 0 1 2
Output example #1
1 2 3 8 4 7 9 10 5 6 11 12