結果
問題 |
No.277 根掘り葉掘り
|
ユーザー |
|
提出日時 | 2015-09-05 01:44:11 |
言語 | PyPy2 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 619 bytes |
コンパイル時間 | 1,385 ms |
コンパイル使用メモリ | 76,288 KB |
実行使用メモリ | 119,684 KB |
最終ジャッジ日時 | 2024-07-19 03:31:14 |
合計ジャッジ時間 | 6,067 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 RE * 7 |
ソースコード
#!/usr/bin/python from collections import defaultdict import sys if sys.version_info[0]>=3: raw_input=input def dfs(n,d,z): r=None for e in H[n]: if e not in z: z[e]=1 if r is None: r=1<<29 x=dfs(e,d+1,z) r=min(r,x+1) del z[e] if r is None: r=0 R[n]=min(r,d) L[n]=r return r def dfs2(n,d,z): for e in H[n]: if e not in z: z[e]=1 dfs2(e,min(d,L[n])+1,z) del z[e] R[n]=min(R[n],d) n=int(raw_input()) H=defaultdict(list) R={} L={} for _ in range(n-1): x,y=map(int,raw_input().split()) H[x].append(y) H[y].append(x) dfs(1,0,{1:1}) dfs2(1,0,{1:1}) for i in range(1,n+1):print(R[i])