結果

問題 No.2532 Want Play More
コンテスト
ユーザー norioc
提出日時 2026-11-26 03:34:05
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,004 ms / 2,000 ms
+ 631µs
コード長 656 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 81 ms
コンパイル使用メモリ 64,364 KB
実行使用メモリ 345,380 KB
最終ジャッジ日時 2026-11-26 03:34:18
合計ジャッジ時間 11,578 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 1 << 62
N = int(input())

adj = defaultdict(list)
for _ in range(N-1):
    U, V = map(lambda x: int(x)-1, input().split())
    adj[U].append(V)
    adj[V].append(U)


HALC = 0
SAPP = 1

def tree_dp(v, par, side):
    res = -INF if side == HALC else INF

    for to in adj[v]:
        if to == par: continue

        r = tree_dp(to, v, side ^ 1) + 1
        if side == HALC:
            res = max(res, r)
        else:
            res = min(res, r)

    if res in (-INF, INF):
        return 0

    return res


a = tree_dp(0, -1, 0)
b = tree_dp(0, -1, 1)
print(a)
print(b)
0