EISCOPN - Question 3
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:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
You are given an undirected graph that has ~n~ vertices and ~m~ edges. You are also given ~q~ queries, each of them contains two vertices ~a~ and ~b~. You should check if there is a path between ~a~ and ~b~.
Input
- The first line contains ~3~ integers ~n, m, q~ ~(0 < n, m ≤ 10^5)~.
- Each of the next ~m~ lines contains two integers ~u, v~ representing an edge connecting vertex ~u~ and vertex ~v~ ~(0 ≤ u, v < n)~.
- Each of the next ~q~ lines contains two integers ~a~ and ~b~, representing a query ~(0 ≤ a, b < n)~.
Output
- For each query, print
YESif there is a path between two vertices, otherwise printNO. The output is case-sensitive.
Sample Input
5 4 3
0 1
1 2
2 3
0 3
1 3
1 0
0 4
Sample Output
YES
YES
NO
Bình luận