結果
問題 | No.912 赤黒木 |
ユーザー | mkawa2 |
提出日時 | 2023-09-21 23:48:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,817 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,024 KB |
実行使用メモリ | 181,816 KB |
最終ジャッジ日時 | 2024-07-07 16:43:26 |
合計ジャッジ時間 | 17,899 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,612 KB |
testcase_01 | AC | 39 ms
53,192 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 740 ms
181,816 KB |
testcase_23 | AC | 757 ms
180,356 KB |
testcase_24 | AC | 751 ms
180,780 KB |
testcase_25 | AC | 788 ms
150,588 KB |
testcase_26 | AC | 871 ms
150,052 KB |
testcase_27 | AC | 815 ms
153,820 KB |
testcase_28 | AC | 686 ms
132,196 KB |
testcase_29 | AC | 651 ms
125,884 KB |
testcase_30 | AC | 740 ms
130,820 KB |
testcase_31 | AC | 702 ms
127,840 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 << 63) # md = 10**9+7 md = 998244353 n = II() deg = [0]*n to = [[] for _ in range(n)] for _ in range(n-1): u, v = LI1() to[u].append(v) to[v].append(u) for _ in range(n-1): u, v = LI1() deg[u] ^= 1 deg[v] ^= 1 def dfs(root=0): uu, stack = [], [root] while stack: u = stack.pop() uu.append(u) for v in to[u]: if v == parent[u]: continue parent[v] = u depth[v] = depth[u]+1 stack.append(v) return uu parent, depth = [-1]*n, [0]*n uu = dfs() to2 = [[] for _ in range(n)] ans = n-1 for u in uu[:0:-1]: if deg[u]: p = parent[u] to2[u].append(p) to2[p].append(u) ans += 1 deg[p] ^= 1 to = to2 fin = [0]*n parent, depth = [-1]*n, [0]*n mx = 0 for u in range(n): if fin[u]: continue uu = dfs(u) mxd = mxu = -1 for u in uu: fin[u] = 1 if depth[u] > mxd: mxd = depth[u] mxu = u depth[mxu] = 0 parent[mxu] = -1 dfs(mxu) for u in uu: mx = max(mx, depth[u]) print(ans-mx)