Submit | All submissions | Best solutions | Back to list |
EI23241Q1 - Connected graph |
You are given a set of undirected graphs. Your task is to determine if each graph is connected.
Input
- The first line contains an integer T (1 ≤ T ≤ 100), the number of graphs
- For each graph:
- The first line contains two integers N (1 ≤ N ≤ 104) and M (1 ≤ M ≤ 2*104), the number of vertices and edges respectively.
- The next M lines, each contains two integers u and v (1 ≤ u, v ≤ N) representing an edge between vertices u and v.
Output
For each graph, print "YES" if the graph is connected, and "NO" otherwise
Example
Input: 2 4 3 1 2 2 3 3 4 3 1 1 2 Output: YES NO
Added by: | Ha Minh Ngoc |
Date: | 2024-10-26 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |