#C7206. All Parks Reachable
All Parks Reachable
All Parks Reachable
You are given n parks and m unidirectional paths connecting these parks. Each path connects park u to park v. Your task is to determine whether every park is reachable from every other park. In other words, whether for any two parks u and v, there exists a directed path from u to v.
This condition is satisfied if the directed graph is strongly connected. More formally, given a directed graph \(G=(V,E)\) with \(|V| = n\) and \(|E| = m\), the graph is strongly connected if for every pair of vertices \(u,v\), there is a path from \(u\) to \(v\).
If the graph is strongly connected, output "YES"; otherwise, output "NO".
inputFormat
The first line contains two integers n and m, representing the number of parks and the number of paths, respectively.
The next m lines each contain two integers u and v, indicating a directed path from park u to park v.
outputFormat
Output a single line containing "YES" if every park is reachable from every other park, and "NO" otherwise.
## sample4 4
1 2
2 3
3 4
4 2
NO