結果
| 問題 | No.2677 Minmax Independent Set |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-26 12:12:23 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
RE
不安定
|
| 実行時間 | - |
| コード長 | 627 bytes |
| 記録 | |
| コンパイル時間 | 249 ms |
| コンパイル使用メモリ | 95,552 KB |
| 実行使用メモリ | 276,940 KB |
| 最終ジャッジ日時 | 2026-09-06 19:10:46 |
| 合計ジャッジ時間 | 9,848 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 RE * 5 TLE * 1 -- * 53 |
ソースコード
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)