結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-02 15:50:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 361 ms / 2,000 ms |
| コード長 | 778 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 82,444 KB |
| 実行使用メモリ | 189,832 KB |
| 最終ジャッジ日時 | 2025-03-22 10:42:19 |
| 合計ジャッジ時間 | 7,625 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
import sys
from typing import List
sys.setrecursionlimit(int(1e9))
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
n = int(input())
adjList = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = map(int, input().split())
u, v = u - 1, v - 1
adjList[u].append(v)
adjList[v].append(u)
def dfs(cur: int, pre: int) -> List[int]:
res = [1, 0] # 不删除/删除当前节点后的最大连通分量数
for next in adjList[cur]:
if next == pre:
continue
nextRes = dfs(next, cur)
res[0] += max(nextRes[0] - 1, nextRes[1])
res[1] += max(nextRes[0], nextRes[1])
return res
res = dfs(0, -1)
print(max(res))