mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 16:36:28 +00:00
parent
df8953662e
commit
7a684f220c
34
LibreOJ/109/109.cpp
Normal file
34
LibreOJ/109/109.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int mod = 998244353;
|
||||
|
||||
int n, m, op, u, v, fa[4000005];
|
||||
long long ans;
|
||||
|
||||
int find(int x) {
|
||||
return x == fa[x] ? x : fa[x] = find(fa[x]);
|
||||
}
|
||||
|
||||
void merge(int x, int y) {
|
||||
fa[find(x)] = find(y);
|
||||
}
|
||||
|
||||
int main() {
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 0; i <= n; i++) {
|
||||
fa[i] = i;
|
||||
}
|
||||
for (int i = 1; i <= m; i++) {
|
||||
scanf("%d%d%d", &op, &u, &v);
|
||||
if (op == 0) {
|
||||
merge(u, v);
|
||||
} else {
|
||||
ans <<= 1ll, ans |= 1ll * (find(u) == find(v));
|
||||
}
|
||||
ans %= mod;
|
||||
}
|
||||
printf("%lld\n", ans);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user