結果

問題 No.2677 Minmax Independent Set
ユーザー fiblonaria
提出日時 2024-03-26 12:12:23
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 627 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 280,516 KB
最終ジャッジ日時 2024-09-30 14:14:15
合計ジャッジ時間 8,501 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 RE * 5 TLE * 1 -- * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache

@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)

ans = float('inf')
for i in range(N):
    temp = 1
    for u in con[i]:
        temp += white(u, i)
    ans = min(ans, temp)
print(ans)


0