結果

問題 No.277 根掘り葉掘り
ユーザー chocoruskchocorusk
提出日時 2020-09-19 00:27:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 437 ms / 3,000 ms
コード長 563 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 28,828 KB
最終ジャッジ日時 2023-09-04 14:37:29
合計ジャッジ時間 7,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,420 KB
testcase_01 AC 19 ms
8,544 KB
testcase_02 AC 19 ms
8,480 KB
testcase_03 AC 19 ms
8,564 KB
testcase_04 AC 19 ms
8,508 KB
testcase_05 AC 18 ms
8,600 KB
testcase_06 AC 18 ms
8,600 KB
testcase_07 AC 19 ms
8,416 KB
testcase_08 AC 19 ms
8,584 KB
testcase_09 AC 417 ms
28,828 KB
testcase_10 AC 338 ms
27,124 KB
testcase_11 AC 423 ms
27,516 KB
testcase_12 AC 420 ms
27,612 KB
testcase_13 AC 437 ms
27,988 KB
testcase_14 AC 416 ms
28,192 KB
testcase_15 AC 409 ms
27,560 KB
testcase_16 AC 420 ms
27,480 KB
testcase_17 AC 418 ms
27,844 KB
testcase_18 AC 412 ms
27,700 KB
testcase_19 AC 429 ms
27,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
from collections import deque
n=int(readline())
g=[[] for _ in range(n)]
for _ in range(n-1):
    x, y=map(int, readline().split())
    x-=1
    y-=1
    g[x].append(y)
    g[y].append(x)
INF=10**9
d=[INF]*n
que=deque()
for x in range(n):
    if x==0 or len(g[x])==1:
        d[x]=0
        que.append(x)
while que:
    x=que.popleft()
    for y in g[x]:
        if d[y]>d[x]+1:
            d[y]=d[x]+1
            que.append(y)
for x in d:
    print(x)
0