結果

問題 No.2532 Want Play More
ユーザー mkawa2mkawa2
提出日時 2023-11-03 23:20:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 129,436 KB
最終ジャッジ日時 2023-11-03 23:21:08
合計ジャッジ時間 8,600 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,660 KB
testcase_01 AC 547 ms
118,484 KB
testcase_02 AC 488 ms
118,488 KB
testcase_03 AC 485 ms
111,712 KB
testcase_04 AC 520 ms
111,372 KB
testcase_05 AC 496 ms
114,668 KB
testcase_06 AC 229 ms
117,100 KB
testcase_07 AC 106 ms
76,896 KB
testcase_08 AC 121 ms
77,852 KB
testcase_09 AC 115 ms
77,980 KB
testcase_10 AC 267 ms
95,480 KB
testcase_11 AC 262 ms
94,672 KB
testcase_12 AC 415 ms
108,056 KB
testcase_13 AC 286 ms
98,772 KB
testcase_14 AC 154 ms
83,396 KB
testcase_15 AC 493 ms
118,204 KB
testcase_16 AC 440 ms
111,896 KB
testcase_17 AC 113 ms
77,656 KB
testcase_18 AC 331 ms
102,620 KB
testcase_19 AC 461 ms
109,556 KB
testcase_20 AC 37 ms
53,660 KB
testcase_21 AC 37 ms
53,660 KB
testcase_22 AC 37 ms
53,660 KB
testcase_23 AC 37 ms
53,660 KB
testcase_24 AC 37 ms
53,660 KB
testcase_25 AC 37 ms
53,660 KB
testcase_26 AC 37 ms
53,660 KB
testcase_27 AC 38 ms
53,660 KB
testcase_28 AC 216 ms
129,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

n=II()
if n==1:
    print(0)
    print(0)
    exit()
to=[[] for _ in range(n)]
for _ in range(n-1):
    u,v=LI1()
    to[u].append(v)
    to[v].append(u)

def dfs(root=0):
    uu, stack = [], [root]
    while stack:
        u = stack.pop()
        uu.append(u)
        for v in to[u]:
            if v == parent[u]: continue
            parent[v] = u
            depth[v] = depth[u]+1
            stack.append(v)
    return uu

parent, depth = [-1]*n, [0]*n
uu=dfs()

for case in range(2):
    dp=[0]*n
    for u in uu[::-1]:
        if u and len(to[u])==1:continue
        if depth[u]&1^case:
            dp[u]=n
            for v in to[u]:
                if v==parent[u]:continue
                dp[u]=min(dp[u],dp[v]+1)
        else:
            dp[u]=0
            for v in to[u]:
                if v==parent[u]:continue
                dp[u]=max(dp[u],dp[v]+1)

    print(dp[0])
0