1 条题解
-
0
参考答案:
#include<iostream> using namespace std; const int N = 100010; int p[N]; int n, m; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x]; } int main() { char c; cin >> n >> m; for (int i = 1; i <= n; ++i) p[i] = i; while (m--) { int a, b; cin >> c >> a >> b; if (c == 'M') p[find(a)] = find(b); else { if (find(a) == find(b)) cout << "Yes" << endl; else cout << "No" << endl; } } return 0; }
- 1
信息
- ID
- 84
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 4
- 已通过
- 2
- 上传者