結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー | shotoyoo |
提出日時 | 2023-04-21 21:46:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,482 bytes |
コンパイル時間 | 314 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 97,104 KB |
最終ジャッジ日時 | 2024-11-08 06:28:05 |
合計ジャッジ時間 | 15,112 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
54,784 KB |
testcase_01 | AC | 48 ms
54,784 KB |
testcase_02 | AC | 49 ms
54,912 KB |
testcase_03 | AC | 295 ms
86,528 KB |
testcase_04 | AC | 331 ms
95,172 KB |
testcase_05 | AC | 222 ms
93,188 KB |
testcase_06 | AC | 247 ms
83,968 KB |
testcase_07 | AC | 245 ms
83,456 KB |
testcase_08 | AC | 196 ms
96,768 KB |
testcase_09 | AC | 284 ms
92,612 KB |
testcase_10 | AC | 205 ms
81,536 KB |
testcase_11 | AC | 183 ms
79,360 KB |
testcase_12 | AC | 168 ms
80,896 KB |
testcase_13 | AC | 270 ms
84,736 KB |
testcase_14 | AC | 178 ms
82,048 KB |
testcase_15 | AC | 208 ms
90,928 KB |
testcase_16 | AC | 251 ms
83,584 KB |
testcase_17 | AC | 190 ms
79,360 KB |
testcase_18 | AC | 323 ms
96,660 KB |
testcase_19 | AC | 321 ms
94,176 KB |
testcase_20 | AC | 283 ms
88,340 KB |
testcase_21 | AC | 217 ms
83,072 KB |
testcase_22 | AC | 257 ms
87,236 KB |
testcase_23 | WA | - |
testcase_24 | AC | 261 ms
87,488 KB |
testcase_25 | AC | 285 ms
95,528 KB |
testcase_26 | AC | 161 ms
95,360 KB |
testcase_27 | WA | - |
testcase_28 | AC | 215 ms
89,696 KB |
testcase_29 | AC | 262 ms
91,220 KB |
testcase_30 | AC | 200 ms
80,512 KB |
testcase_31 | WA | - |
testcase_32 | AC | 249 ms
92,508 KB |
testcase_33 | AC | 306 ms
92,540 KB |
testcase_34 | AC | 281 ms
87,040 KB |
testcase_35 | AC | 136 ms
93,696 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 141 ms
85,760 KB |
testcase_41 | WA | - |
testcase_42 | AC | 257 ms
83,840 KB |
testcase_43 | AC | 324 ms
91,136 KB |
testcase_44 | AC | 364 ms
97,104 KB |
testcase_45 | AC | 360 ms
94,916 KB |
testcase_46 | AC | 373 ms
94,736 KB |
testcase_47 | AC | 358 ms
95,044 KB |
testcase_48 | AC | 349 ms
94,964 KB |
testcase_49 | AC | 319 ms
90,880 KB |
testcase_50 | AC | 328 ms
91,008 KB |
testcase_51 | AC | 308 ms
91,136 KB |
testcase_52 | AC | 316 ms
91,520 KB |
ソースコード
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda : list(map(int, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()] def debug(_l_): for s in _l_.split(): print(f"{s}={eval(s)}", end=" ") print() def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] class UF: # unionfind def __init__(self, n): self.n = n self.parent = list(range(n)) self.size = [1] * n # self.es = [0] * n def check(self): return [self.root(i) for i in range(self.n)] def root(self, i): inter = set() while self.parent[i]!=i: inter.add(i) i = self.parent[i] r = i for i in inter: self.parent[i] = r return r def merge(self, i, j): # 繋いだかどうかを返す ri = self.root(i) rj = self.root(j) if ri==rj: # self.es[ri] += 1 return False if self.size[ri]>self.size[rj]: ri,rj = rj,ri self.parent[ri] = rj self.size[rj] += self.size[ri] # self.es[rj] += self.es[ri] + 1 return True def rs(self): return sorted(set([self.root(i) for i in range(self.n)])) n,q = list(map(int, input().split())) uf = UF(n) ab = [] for i in range(q): a,b,c = LI() a -= 1 b -= 1 if c==0: uf.merge(a,b) else: ab.append((a,b)) rs = uf.rs() ns = {} M = 998244353 for a,b in ab: ra = uf.root(a) rb = uf.root(b) if ra==rb: ans = 0 break else: ns.setdefault(ra, []).append(rb) ns.setdefault(rb, []).append(ra) num = 0 done = {} for r in rs: if r in done: continue q = [r] done[r] = 0 num += 1 ng = 0 while q: u = q.pop() for v in ns.get(u, []): if v not in done: done[v] = done[u]^1 q.append(v) else: if done[v]==done[u]: ng = 1 break if ng: break if ng: ans = 0 break else: ans = pow(2, num, M) print(ans%M)