結果

問題 No.2532 Want Play More
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-11-04 11:52:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 725 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 144,044 KB
最終ジャッジ日時 2023-11-04 11:52:47
合計ジャッジ時間 10,808 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,568 KB
testcase_01 AC 705 ms
116,928 KB
testcase_02 AC 677 ms
116,924 KB
testcase_03 AC 641 ms
116,332 KB
testcase_04 AC 725 ms
116,052 KB
testcase_05 AC 633 ms
113,368 KB
testcase_06 AC 298 ms
116,396 KB
testcase_07 AC 107 ms
76,700 KB
testcase_08 AC 116 ms
77,528 KB
testcase_09 AC 110 ms
77,428 KB
testcase_10 AC 327 ms
94,716 KB
testcase_11 AC 329 ms
93,900 KB
testcase_12 AC 609 ms
107,020 KB
testcase_13 AC 381 ms
95,832 KB
testcase_14 AC 174 ms
83,856 KB
testcase_15 AC 670 ms
116,640 KB
testcase_16 AC 573 ms
110,856 KB
testcase_17 AC 109 ms
77,356 KB
testcase_18 AC 428 ms
102,376 KB
testcase_19 AC 581 ms
106,672 KB
testcase_20 AC 37 ms
53,568 KB
testcase_21 AC 36 ms
53,568 KB
testcase_22 AC 36 ms
53,568 KB
testcase_23 AC 36 ms
53,568 KB
testcase_24 AC 36 ms
53,568 KB
testcase_25 AC 36 ms
53,568 KB
testcase_26 AC 36 ms
53,568 KB
testcase_27 AC 35 ms
53,568 KB
testcase_28 AC 305 ms
144,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
e = [[] for i in range(n)]
for _ in range(n-1):
    a,b = [int(x)-1 for x in input().split()]
    e[a].append(b)
    e[b].append(a)


depth = [n]*n
q = [0]
topo = []
depth[0] = 0
while q:
    now = q.pop()
    topo.append(now)
    for nex in e[now]:
        if depth[nex] > depth[now]+1:
            depth[nex] = depth[now]+1
            q.append(nex)

def solve(f):
    dp = [-1]*n
    for now in topo[::-1]:

        d = depth[now]%2

        ## max
        if d == f:

            ma = 0

            for nex in e[now]:
                if depth[nex] > depth[now]:
                    ma = max(ma,dp[nex]+1)
            
            dp[now] = ma
            
            

        ## min
        else:
            mi = n+1
            for nex in e[now]:
                if depth[nex] > depth[now]:
                    mi = min(mi,dp[nex]+1)

            
            if mi == n+1:
                mi = 0
            dp[now] = mi
    return dp[0]


print(solve(0))
print(solve(1))
0