結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー | Shirotsume |
提出日時 | 2023-04-21 22:11:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 581 ms / 2,000 ms |
コード長 | 2,334 bytes |
コンパイル時間 | 363 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 108,928 KB |
最終ジャッジ日時 | 2024-11-08 06:33:51 |
合計ジャッジ時間 | 21,869 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
54,272 KB |
testcase_01 | AC | 48 ms
54,144 KB |
testcase_02 | AC | 50 ms
54,784 KB |
testcase_03 | AC | 467 ms
90,464 KB |
testcase_04 | AC | 513 ms
95,236 KB |
testcase_05 | AC | 210 ms
89,548 KB |
testcase_06 | AC | 409 ms
84,480 KB |
testcase_07 | AC | 412 ms
85,672 KB |
testcase_08 | AC | 204 ms
108,928 KB |
testcase_09 | AC | 411 ms
95,452 KB |
testcase_10 | AC | 361 ms
82,308 KB |
testcase_11 | AC | 294 ms
80,048 KB |
testcase_12 | AC | 192 ms
78,116 KB |
testcase_13 | AC | 433 ms
86,756 KB |
testcase_14 | AC | 156 ms
77,312 KB |
testcase_15 | AC | 200 ms
86,624 KB |
testcase_16 | AC | 413 ms
85,504 KB |
testcase_17 | AC | 326 ms
80,952 KB |
testcase_18 | AC | 507 ms
95,432 KB |
testcase_19 | AC | 495 ms
94,628 KB |
testcase_20 | AC | 457 ms
89,512 KB |
testcase_21 | AC | 342 ms
80,676 KB |
testcase_22 | AC | 458 ms
88,112 KB |
testcase_23 | AC | 329 ms
80,112 KB |
testcase_24 | AC | 447 ms
92,376 KB |
testcase_25 | AC | 412 ms
100,404 KB |
testcase_26 | AC | 161 ms
103,040 KB |
testcase_27 | AC | 283 ms
79,276 KB |
testcase_28 | AC | 210 ms
85,400 KB |
testcase_29 | AC | 288 ms
90,020 KB |
testcase_30 | AC | 336 ms
80,108 KB |
testcase_31 | AC | 390 ms
80,632 KB |
testcase_32 | AC | 281 ms
91,616 KB |
testcase_33 | AC | 511 ms
93,660 KB |
testcase_34 | AC | 446 ms
81,612 KB |
testcase_35 | AC | 147 ms
95,616 KB |
testcase_36 | AC | 370 ms
80,876 KB |
testcase_37 | AC | 390 ms
80,008 KB |
testcase_38 | AC | 185 ms
77,904 KB |
testcase_39 | AC | 262 ms
78,480 KB |
testcase_40 | AC | 143 ms
89,216 KB |
testcase_41 | AC | 476 ms
81,748 KB |
testcase_42 | AC | 410 ms
80,636 KB |
testcase_43 | AC | 508 ms
82,964 KB |
testcase_44 | AC | 567 ms
98,752 KB |
testcase_45 | AC | 553 ms
98,296 KB |
testcase_46 | AC | 554 ms
98,264 KB |
testcase_47 | AC | 581 ms
98,648 KB |
testcase_48 | AC | 553 ms
101,632 KB |
testcase_49 | AC | 499 ms
83,200 KB |
testcase_50 | AC | 501 ms
82,308 KB |
testcase_51 | AC | 502 ms
82,188 KB |
testcase_52 | AC | 521 ms
82,712 KB |
ソースコード
import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.num = N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return x self.num -= 1 if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return x def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 def count(self): return self.num n, q = mi() U = dsu(2 * n) for _ in range(q): a, b, c = mi() a -= 1; b -= 1 if c == 0: U.merge(a, b) U.merge(a + n, b + n) else: U.merge(a, n + b) U.merge(a + n, b) for i in range(n): if U.same(i, n + i): print(0) exit() ans = pow(2, len(U.groups()) // 2, mod) print(ans)