結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー |
![]() |
提出日時 | 2023-04-21 21:47:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 517 ms / 2,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 592 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 90,892 KB |
最終ジャッジ日時 | 2024-11-08 06:29:24 |
合計ジャッジ時間 | 20,066 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
class UnionFind:def __init__(self, n):self.n = nself.parents = [-1] * ndef find(self, x):if self.parents[x] < 0:return xelse:self.parents[x] = self.find(self.parents[x])return self.parents[x]def union(self, x, y):x = self.find(x)y = self.find(y)if x == y:returnif self.parents[x] > self.parents[y]:x, y = y, xself.parents[x] += self.parents[y]self.parents[y] = xmod = 998244353n, q = map(int,input().split())ikeru = [[] for i in range(2*n)]uf = UnionFind(2*n)for i in range(q):a, b, c = map(int,input().split())a-=1; b-=1if c == 0:uf.union(a, b)uf.union(n+a, n+b)else:uf.union(a, n+b)uf.union(n+a, b)ans = 1for i in range(n):if uf.find(i) == uf.find(i+n):ans = 0if uf.find(i) == i:ans *= 2ans %= modprint(ans)