Is There a Route
Given the network and two people S and T, are they connected by some chain of links?
Input: the first line has N and M; each of the next M lines has an edge u v (1-based). The last line has S and T.
Output: YES or NO.
Constraints:
- 1 ≤ N ≤ 104
- 0 ≤ M ≤ 2×104
- multiple edges and self-loops may appear
Sample Tests
Input 1
4 2 1 2 3 4 1 4
Output 1
NO
Input 2
4 3 1 2 2 3 3 4 1 4
Output 2
YES
Discussion (opens after you solve — no spoilers before)
No comments yet.