EI23241Q1 - Connected graph

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

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 \le T \le 100)~, the number of graphs
  • For each graph:
    • The first line contains two integers ~N~ ~(1 \le N \le 10^4)~ and ~M~ ~(1 \le M \le 2 \times 10^4)~, the number of vertices and edges respectively.
    • The next ~M~ lines, each contains two integers ~u~ and ~v~ ~(1 \le u, v \le 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

Example Output

YES
NO

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.