Loading...
Loading...
Loading...
Computers are joined by two-way cables. A loop is a route that leaves a computer, uses distinct cables, and comes back to it. Print YES if the cabling contains a loop and NO otherwise.
Example 1
Input
4 4 0 1 1 2 2 0 2 3
Output
YES
Example 2
Input
4 3 0 1 1 2 2 3
Output
NO
Try the problem first. Open one hint at a time.
Remember which node you came from.
Meeting a seen node that is not the one you came from closes a loop.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor