Clone DAG

A directed acyclic graph (DAG) is a graph that contains no cycles but has directed edges. We got a DAG and we need to clone it, i.e. create another graph with copies of its vertices and the edges connecting them.

example:  

enter:
 
0 - - - > 1 - - - -> 4
|        /  \        ^   
|       /    \       |  
|      /      \      |
|     /        \     |  
|    /          \    |
|   /            \   |
vvv |
2 - - - - - - - - -> 3


Output: Printing the output of the clone graph gives:
0-1
1-2
2-3
3-4
1-3
1-4
0-2

Guess you like

Origin blog.csdn.net/tianqiquan/article/details/130093764