結果

問題 No.2532 Want Play More
ユーザー ああいいああいい
提出日時 2023-11-11 21:38:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 657 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 140,252 KB
最終ジャッジ日時 2023-11-11 21:38:35
合計ジャッジ時間 10,019 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 657 ms
116,808 KB
testcase_02 AC 619 ms
116,680 KB
testcase_03 AC 547 ms
114,712 KB
testcase_04 AC 587 ms
114,312 KB
testcase_05 AC 555 ms
113,248 KB
testcase_06 AC 336 ms
135,044 KB
testcase_07 AC 105 ms
77,072 KB
testcase_08 AC 110 ms
77,712 KB
testcase_09 AC 111 ms
77,712 KB
testcase_10 AC 295 ms
95,436 KB
testcase_11 AC 291 ms
95,036 KB
testcase_12 AC 471 ms
106,472 KB
testcase_13 AC 350 ms
98,632 KB
testcase_14 AC 160 ms
82,192 KB
testcase_15 AC 587 ms
116,280 KB
testcase_16 AC 488 ms
109,788 KB
testcase_17 AC 110 ms
77,328 KB
testcase_18 AC 427 ms
102,496 KB
testcase_19 AC 505 ms
110,720 KB
testcase_20 AC 37 ms
53,460 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 37 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 37 ms
53,460 KB
testcase_25 AC 37 ms
53,460 KB
testcase_26 AC 38 ms
53,460 KB
testcase_27 AC 39 ms
53,460 KB
testcase_28 AC 310 ms
140,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

dp = [[0] * 2 for _ in range(N)]

stack = [(0,-1,0)]
while stack:
    now,parent,f = stack.pop()
    if f == 0:
        stack.append((now,parent,1))
        for i in G[now]:
            if i == parent:continue
            stack.append((i,now,0))
        continue

    M = 0
    m = 10 ** 6
    count = 0
    for v in G[now]:
        if v == parent:continue
        count += 1
        if dp[v][1] > M:M = dp[v][1]
        if dp[v][0] < m:m = dp[v][0]
    if count == 0:
        M = 0
        m = 0
    dp[now][0] = M + 1
    dp[now][1] = m + 1
print(dp[0][0] - 1)
print(dp[0][1] - 1)
    
#print(dp)
0