GRACON - Connectivity
In an undirected graph G, two vertices u and v are connected if G contains a path from u to v. An undirected graph is said to be connected if every pair of vertices in the graph are connected. Given an undirected graph, determine whether the graph is connected or not.
Input
The first line consists of 't', the number of test cases. The first line of each test case consists of 'n' and 'm', the number of vertices and the number of edges respectively. Next 'm' lines consists of 'a' and 'b' meaning that there is an edge between vertices 'a' and 'b'.
Output
Print "YES" (without quotes) if the graph is connected and "NO" (without quotes) otherwise.
Example
Input: 1 3 2 1 2 2 3 Output: YES
Added by: | 785227 |
Date: | 2014-07-17 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C C++ 4.3.2 CPP JAVA PYTHON |
Resource: | Own |