- [NOI2015] 程序自动分析
code
- @ 2026-2-7 10:50:21
void solve() {
int n;
cin >> n;
vector<array<int, 3>> opt(n);
map<int, int> f;
for (int i = 0; i < n; i++) {
int o, x, y;
cin >> x >> y >> o;
opt[i] = {o, x, y};
f[x] = x;
f[y] = y;
}
function<int(int)> find = [&] (int u) {
return u == f[u] ? u : f[u] = find(f[u]);
};
auto merge = [&] (int u, int v) {
f[find(u)] = find(v);
};
for (auto [o, x, y] : opt) {
if (o == 1) {
merge(x, y);
}
}
for (auto [o, x, y] : opt) {
if (o == 0) {
if (find(x) == find(y)) {
cout << "NO\n";
return;
}
}
}
cout << "YES\n";
}
0 条评论
目前还没有评论...
信息
- ID
- 423
- 时间
- ms
- 内存
- MiB
- 难度
- 6
- 标签
- 递交数
- 26
- 已通过
- 12
- 上传者