結果
問題 | No.912 赤黒木 |
ユーザー | mkawa2 |
提出日時 | 2023-09-21 23:41:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,816 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 182,520 KB |
最終ジャッジ日時 | 2024-07-07 16:37:47 |
合計ジャッジ時間 | 19,190 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
59,404 KB |
testcase_01 | AC | 40 ms
52,800 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 | 748 ms
181,944 KB |
testcase_23 | AC | 863 ms
182,520 KB |
testcase_24 | AC | 830 ms
182,328 KB |
testcase_25 | AC | 800 ms
150,220 KB |
testcase_26 | AC | 853 ms
149,916 KB |
testcase_27 | AC | 831 ms
153,952 KB |
testcase_28 | TLE | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
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 = 0 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)