結果
問題 |
No.2677 Minmax Independent Set
|
ユーザー |
|
提出日時 | 2024-03-26 12:20:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 669 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 386,364 KB |
最終ジャッジ日時 | 2024-09-30 14:14:27 |
合計ジャッジ時間 | 4,661 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 2 TLE * 1 -- * 58 |
ソースコード
from functools import cache import sys @cache def black(v, p): ans = 1 for u in con[v]: if u == p: continue ans += white(u, v) return ans @cache def white(v, p): ans = 0 for u in con[v]: if u == p: continue ans += max(black(u, v), white(u, v)) return ans N = int(input()) con = [set() for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) con[a - 1].add(b - 1) con[b - 1].add(a - 1) sys.setrecursionlimit(N * 10) ans = float('inf') for i in range(N): temp = 0 for u in con[i]: temp += white(u, i) ans = min(ans, temp) print(ans)