結果
問題 | No.277 根掘り葉掘り |
ユーザー |
|
提出日時 | 2023-01-18 07:08:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 266 ms / 3,000 ms |
コード長 | 786 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 94,804 KB |
最終ジャッジ日時 | 2024-06-11 10:27:05 |
合計ジャッジ時間 | 5,541 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) e = [[] for _ in range(N)] for _ in range(N-1): x,y = map(int,input().split()) x -= 1 y -= 1 e[x].append(y) e[y].append(x) v = deque() R = [-1]*N L = [-1]*N R[0]=0 v.append(0) while v: x = v.popleft() for ix in e[x]: if R[ix]!=-1: continue R[ix] = R[x] + 1 v.append(ix) for i in range(1,N): if len(e[i])==1: L[i]=0 v.append(i) while v: x = v.popleft() for ix in e[x]: if L[ix]!=-1: continue L[ix] = L[x] + 1 v.append(ix) for i in range(N): print(min(R[i],L[i]))