結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー | tassei903 |
提出日時 | 2023-04-21 21:58:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 663 ms / 2,000 ms |
コード長 | 2,055 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 101,748 KB |
最終ジャッジ日時 | 2024-11-08 06:21:00 |
合計ジャッジ時間 | 19,440 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
53,888 KB |
testcase_01 | AC | 47 ms
54,400 KB |
testcase_02 | AC | 47 ms
54,400 KB |
testcase_03 | AC | 392 ms
85,760 KB |
testcase_04 | AC | 438 ms
91,736 KB |
testcase_05 | AC | 199 ms
94,720 KB |
testcase_06 | AC | 349 ms
82,388 KB |
testcase_07 | AC | 361 ms
83,652 KB |
testcase_08 | AC | 198 ms
101,748 KB |
testcase_09 | AC | 364 ms
91,256 KB |
testcase_10 | AC | 297 ms
79,944 KB |
testcase_11 | AC | 252 ms
78,544 KB |
testcase_12 | AC | 164 ms
77,616 KB |
testcase_13 | AC | 373 ms
83,852 KB |
testcase_14 | AC | 141 ms
77,184 KB |
testcase_15 | AC | 199 ms
91,136 KB |
testcase_16 | AC | 367 ms
84,072 KB |
testcase_17 | AC | 279 ms
79,616 KB |
testcase_18 | AC | 431 ms
92,776 KB |
testcase_19 | AC | 430 ms
91,904 KB |
testcase_20 | AC | 418 ms
88,676 KB |
testcase_21 | AC | 288 ms
79,476 KB |
testcase_22 | AC | 374 ms
85,180 KB |
testcase_23 | AC | 304 ms
80,388 KB |
testcase_24 | AC | 386 ms
86,080 KB |
testcase_25 | AC | 360 ms
97,212 KB |
testcase_26 | AC | 164 ms
100,708 KB |
testcase_27 | AC | 266 ms
79,436 KB |
testcase_28 | AC | 204 ms
89,600 KB |
testcase_29 | AC | 251 ms
91,264 KB |
testcase_30 | AC | 299 ms
80,936 KB |
testcase_31 | AC | 380 ms
85,248 KB |
testcase_32 | AC | 253 ms
91,008 KB |
testcase_33 | AC | 421 ms
90,672 KB |
testcase_34 | AC | 403 ms
88,512 KB |
testcase_35 | AC | 129 ms
92,288 KB |
testcase_36 | AC | 359 ms
84,624 KB |
testcase_37 | AC | 345 ms
82,416 KB |
testcase_38 | AC | 162 ms
77,312 KB |
testcase_39 | AC | 232 ms
78,656 KB |
testcase_40 | AC | 138 ms
92,928 KB |
testcase_41 | AC | 435 ms
88,848 KB |
testcase_42 | AC | 390 ms
86,080 KB |
testcase_43 | AC | 663 ms
96,596 KB |
testcase_44 | AC | 464 ms
97,716 KB |
testcase_45 | AC | 470 ms
95,104 KB |
testcase_46 | AC | 472 ms
95,464 KB |
testcase_47 | AC | 464 ms
94,012 KB |
testcase_48 | AC | 478 ms
94,776 KB |
testcase_49 | AC | 489 ms
95,616 KB |
testcase_50 | AC | 482 ms
96,176 KB |
testcase_51 | AC | 473 ms
95,752 KB |
testcase_52 | AC | 471 ms
95,288 KB |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: 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: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) mod = 998244353 n, q = na() uf = UnionFind(n*2) for _ in range(q): a,b,c = na() a-=1 b-=1 if c == 0: uf.union(a, b) uf.union(a+n,b+n) else: uf.union(a, b+n) uf.union(a+n, b) d = uf.all_group_members() cnt = 0 for i in d: i %= n if uf.same(i, i+n): print(0) exit() else: cnt += 1 print(pow(2, cnt//2, mod))