A city is checking old water pipelines between junctions. If the pipeline map contains a closed loop, water can keep circulating in that loop and pressure analysis becomes harder.
Given the pipeline connections, determine whether there is at least one loop.
The twist: a loop may be hidden inside a larger connected area, not just visible from adjacent edges.
The first line contains two integers KaTeX can only parse string typed expression and KaTeX can only parse string typed expression — the number of junctions and pipelines.
Each of the next KaTeX can only parse string typed expression lines contains two integers KaTeX can only parse string typed expression and KaTeX can only parse string typed expression, meaning there is a two-way pipeline between junctions KaTeX can only parse string typed expression and KaTeX can only parse string typed expression.
Print KaTeX can only parse string typed expression if the pipeline network contains a loop, otherwise print KaTeX can only parse string typed expression.
Input
4 4
1 2
2 3
3 1
3 4OutputYESExplanationJunctions KaTeX can only parse string typed expression form a loop.
Example 2:
Input
5 4
1 2
1 3
3 4
4 5OutputNOExplanationThe network is a tree-like structure with no closed loop.