結果

問題 No.277 根掘り葉掘り
ユーザー konsin_tokagekonsin_tokage
提出日時 2018-03-13 07:58:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 592 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 96,000 KB
最終ジャッジ日時 2024-04-28 20:33:55
合計ジャッジ時間 5,737 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 46 ms
51,584 KB
testcase_02 WA -
testcase_03 AC 43 ms
52,352 KB
testcase_04 AC 44 ms
52,992 KB
testcase_05 AC 48 ms
52,480 KB
testcase_06 AC 44 ms
52,608 KB
testcase_07 AC 43 ms
52,224 KB
testcase_08 AC 41 ms
52,096 KB
testcase_09 AC 231 ms
96,000 KB
testcase_10 AC 213 ms
93,100 KB
testcase_11 AC 243 ms
92,352 KB
testcase_12 AC 226 ms
92,416 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)
parent = [0]*n
R = [0]*n
L = [n]*n
nodes = [0]
for i in nodes:
    for j in graph[i]:
        if j == parent[i]:
            continue
        parent[j] = i
        R[j] = R[i]+1
        if len(graph[j]) == 1:
            L[j] = 0
            while L[parent[j]] > L[j]+1:
                L[parent[j]] = L[j]+1
                j = parent[j]
        else:
            nodes.append(j)
for i in map(min, R, L):
    print(i)
0