#C695. Critical Road Network
Critical Road Network
Critical Road Network
You are given a road network connecting n cities with m bidirectional roads. Your task is to determine whether the road network remains connected if any single road is removed. In other words, you need to decide if the network is 2-edge-connected i.e., there is no critical road (bridge) whose removal disconnects the network.
If there exists at least one road whose removal disconnects the network, output NO
. Otherwise, output YES
.
Note: A bridge in a graph is an edge which, when removed, increases the number of connected components. The algorithm should find bridges using a DFS-based approach. In terms of formula, if \(\text{low}[v] > \text{disc}[u]\) for an edge \((u, v)\), then this edge is a bridge.
inputFormat
The input is given from standard input (stdin
) and has the following format:
- The first line contains two integers n and m separated by a space, where n is the number of cities and m is the number of roads.
- The next m lines each contain two integers u and v representing a bidirectional road connecting cities u and v.
outputFormat
Output a single line to standard output (stdout
) containing YES
if the road network remains connected after removing any single road, and NO
otherwise.
5 5
1 2
2 3
3 4
4 5
5 1
YES