4 solutions
-
0
n, m, p = map(int, input().split()) f = [i for i in range(n+1)] def find(x): if(f[x]!=x): f[x] = find(f[x]) return f[x] def union(a, b): a = find(a) b = find(b) if(a != b): f[a] = b for _ in range(m): a, b = map(int, input().split()) union(a, b) for _ in range(p): i, j = map(int, input().split()) print("Yes" if find(i)==find(j) else "No")
Information
- ID
- 1257
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 4
- Tags
- # Submissions
- 141
- Accepted
- 66
- Uploaded By