Get your own website
Python
C
Java
 
Python result:
C result:
Java result:
Union: A + B
[1, 1, 2, 3, 4, 5, 6]

Union: B + C
[1, 2, 2, 3, 4, 5, 6]

Union: C + D
[1, 2, 3, 3, 4, 5, 6]

Graph has cycle: True
Union: A + B
Union: B + C
Union: C + D
Graph has cycle: true
Union: A + B
[1, 1, 2, 3, 4, 5, 6]

Union: B + C
[1, 2, 2, 3, 4, 5, 6]

Union: C + D
[1, 2, 3, 3, 4, 5, 6]

Graph has cycle: true