結果
問題 | No.768 Tapris and Noel play the game on Treeone |
ユーザー | mkawa2 |
提出日時 | 2024-11-05 23:57:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 346 ms / 2,000 ms |
コード長 | 2,060 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 109,720 KB |
最終ジャッジ日時 | 2024-11-05 23:57:44 |
合計ジャッジ時間 | 7,825 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,048 KB |
testcase_01 | AC | 38 ms
52,340 KB |
testcase_02 | AC | 39 ms
53,284 KB |
testcase_03 | AC | 54 ms
65,876 KB |
testcase_04 | AC | 59 ms
69,360 KB |
testcase_05 | AC | 63 ms
66,464 KB |
testcase_06 | AC | 61 ms
63,400 KB |
testcase_07 | AC | 236 ms
93,208 KB |
testcase_08 | AC | 156 ms
84,824 KB |
testcase_09 | AC | 172 ms
86,612 KB |
testcase_10 | AC | 151 ms
84,936 KB |
testcase_11 | AC | 327 ms
100,248 KB |
testcase_12 | AC | 309 ms
100,540 KB |
testcase_13 | AC | 295 ms
100,404 KB |
testcase_14 | AC | 315 ms
100,908 KB |
testcase_15 | AC | 329 ms
103,296 KB |
testcase_16 | AC | 346 ms
102,788 KB |
testcase_17 | AC | 342 ms
104,436 KB |
testcase_18 | AC | 249 ms
105,620 KB |
testcase_19 | AC | 265 ms
109,720 KB |
testcase_20 | AC | 273 ms
101,988 KB |
testcase_21 | AC | 253 ms
98,552 KB |
20evil_special_uni1.txt | AC | 321 ms
103,908 KB |
20evil_special_uni2.txt | AC | 308 ms
101,656 KB |
ソースコード
import sys sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) md = 10**9+7 # md = 998244353 n = II() to = [[] for _ in range(n)] for _ in range(n-1): u, v = LI1() to[u].append(v) to[v].append(u) def rerooting(root=0): uu = [] stack = [root] while stack: u = stack.pop() uu.append(u) vv = [] # !!!check the format of the "to"!!! for v in to[u]: if v == par[u]: continue vv.append(v) par[v] = u stack.append(v) rdp[v] = dp[u] to[u] = vv # bottom up for u in uu[::-1]: p = par[u] if p != -1: trans_up(u) dp[p] = op(dp[p], dp[u]) # top down for u in uu: cs = e() # !!!check the format of the "to"!!! for v in to[u]: rdp[v] = op(rdp[v], cs) cs = op(cs, dp[v]) cs = rdp[u] for v in to[u][::-1]: rdp[v] = op(rdp[v], cs) trans_down(v) cs = op(cs, dp[v]) dp[u] = cs def op(a, b): return a & b # u to parent[u] def trans_up(u): dp[u] ^= 1 return # parent[u] to u def trans_down(u): rdp[u] ^= 1 return e = lambda: 1 par = [-1]*n # dp初期化 dp = [e() for _ in range(n)] rdp = [e() for _ in range(n)] rerooting() print(sum(dp)) for u in range(n): if dp[u]:print(u+1)