#C11114. Strongly Connected Transporters
Strongly Connected Transporters
Strongly Connected Transporters
Given a directed graph with ( n ) locations (nodes) and ( m ) directional transporters (edges), determine whether the graph is strongly connected. A graph is strongly connected if for every pair of vertices ( u ) and ( v ), there is a path from ( u ) to ( v ) and a path from ( v ) to ( u ).
Input consists of two integers ( n ) and ( m ) in the first line, followed by ( m ) lines each containing two integers ( u ) and ( v ), representing a transporter from ( u ) to ( v ).
Output "YES" if the graph is strongly connected, otherwise "NO".
inputFormat
The first line contains two integers ( n ) and ( m ) separated by a space, where ( n ) is the number of locations and ( m ) is the number of directional transporters.
Then, ( m ) lines follow, each containing two integers ( u ) and ( v ) indicating a transporter from location ( u ) to location ( v ).
outputFormat
Output a single line containing "YES" if the system is strongly connected, or "NO" otherwise.## sample
4 5
1 2
2 3
3 4
4 2
4 1
YES