結果
問題 | No.277 根掘り葉掘り |
ユーザー |
![]() |
提出日時 | 2022-09-22 00:07:08 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 821 bytes |
コンパイル時間 | 196 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 47,616 KB |
最終ジャッジ日時 | 2024-12-22 04:28:06 |
合計ジャッジ時間 | 11,496 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 WA * 8 |
ソースコード
N=int(input()) E=[[] for i in range(N)] for i in range(N-1): x,y=map(int,input().split()) x-=1 y-=1 E[x].append(y) E[y].append(x) ROOT=0 QUE=[ROOT] Parent=[-1]*(N+1) Parent[ROOT]=N # ROOTの親を定めておく. Child=[[] for i in range(N+1)] TOP_SORT=[] # トポロジカルソート DEG=[1<<30]*N DEG[0]=0 while QUE: # トポロジカルソートと同時に親を見つける x=QUE.pop() TOP_SORT.append(x) for to in E[x]: if Parent[to]==-1: Parent[to]=x Child[x].append(to) QUE.append(to) DEG[to]=DEG[x]+1 DEG2=[1<<30]*N for x in TOP_SORT[::-1]: if DEG2[x]==1<<30: DEG2[x]=0 if 0<=Parent[x]<N: DEG2[Parent[x]]=min(DEG2[x]+1,DEG2[Parent[x]]) for i in range(N): print(min(DEG[i],DEG2[i]))