CT034

Cycle Detection in Realm Map

MediumAcceptance: 0.0%

The Codetikki cartographers have drawn a map of realm connections. They need to determine if the map contains any circular routes (cycles). Given an undirected graph, determine if it contains a cycle. Output "true" or "false". Input: first line n vertices and m edges, then m lines each with two vertices u v representing an edge.

Example 1:

Input: 5 5 0 1 1 2 2 3 3 4 4 0
Output: true

Example 2:

Input: 5 4 0 1 1 2 2 3 3 4
Output: false

Constraints:

1 <= n <= 10^5 0 <= m <= 10^5 Vertices are labeled 0 to n-1

Tags:

graph dfs
Loading...
Test Cases:No test cases
No test cases available.