結果

問題 No.277 根掘り葉掘り
ユーザー mkawa2mkawa2
提出日時 2020-02-05 11:13:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 621 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 11,844 KB
実行使用メモリ 59,184 KB
最終ジャッジ日時 2023-10-22 05:33:06
合計ジャッジ時間 6,275 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,012 KB
testcase_01 AC 28 ms
10,012 KB
testcase_02 WA -
testcase_03 AC 29 ms
10,020 KB
testcase_04 AC 29 ms
10,020 KB
testcase_05 AC 30 ms
10,020 KB
testcase_06 AC 30 ms
10,020 KB
testcase_07 AC 29 ms
10,020 KB
testcase_08 AC 29 ms
10,012 KB
testcase_09 AC 386 ms
59,184 KB
testcase_10 AC 296 ms
31,844 KB
testcase_11 AC 329 ms
34,256 KB
testcase_12 AC 355 ms
45,388 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from collections import *

def II(): return int(sys.stdin.readline())
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())

def main():
    def dfs(u=0,pu=-1,r=0):
        l=10**9
        for cu in to[u]:
            if cu==pu:continue
            ret=dfs(cu,u,r+1)+1
            if ret<l:l=ret
        if l==10**9:l=0
        ans[u]=min(l,r)
        return l

    n=II()
    to=defaultdict(list)
    for _ in range(n-1):
        x,y=MI1()
        to[x].append(y)
        to[y].append(x)
    ans=[0]*n
    dfs()
    print(*ans,sep="\n")

main()
0