From 7a684f220c2b92ce744ff7c9b0c43a34537048fb Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 3 Jan 2021 00:01:04 +0800 Subject: [PATCH] =?UTF-8?q?#109.=20=E5=B9=B6=E6=9F=A5=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1025519 --- LibreOJ/109/109.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 LibreOJ/109/109.cpp diff --git a/LibreOJ/109/109.cpp b/LibreOJ/109/109.cpp new file mode 100644 index 00000000..68bcb56c --- /dev/null +++ b/LibreOJ/109/109.cpp @@ -0,0 +1,34 @@ +#include + +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; +} \ No newline at end of file