#K82882. Islands Connectivity
Islands Connectivity
Islands Connectivity
Alice wants to visit Bob's house, which is located on one of several islands. The islands are connected by stepping stones. Given an undirected graph \(G = (V, E)\), where the vertices \(V\) represent islands and the edges \(E\) represent stepping stones connecting them, determine whether there exists a path from Alice's island to Bob's island.
Formally, you are given \(n\) islands and \(m\) stepping stones. Each stepping stone connects two islands. You are also provided with the starting island \(s\) (where Alice's house is located) and the destination island \(t\) (where Bob's house is located). Your task is to determine if there is a way to travel from \(s\) to \(t\) using the stepping stones.
inputFormat
The input consists of multiple test cases. The first line contains an integer (T), denoting the number of test cases. For each test case, the first line contains four integers (n), (m), (s), and (t):
- (n): the number of islands
- (m): the number of stepping stones
- (s): the starting island (Alice's house)
- (t): the destination island (Bob's house)
This is followed by (m) lines, each containing two integers (u) and (v) which indicate that there is a stepping stone connecting island (u) and island (v). All islands are 1-indexed.
outputFormat
For each test case, output a single line containing "YES" if there exists a path from island (s) to island (t), and "NO" otherwise.## sample
1
4 4 1 3
1 2
2 3
3 4
4 1
YES
</p>