結果
問題 |
No.277 根掘り葉掘り
|
ユーザー |
|
提出日時 | 2016-09-21 17:37:05 |
言語 | PyPy2 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 794 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 76,672 KB |
実行使用メモリ | 328,408 KB |
最終ジャッジ日時 | 2024-11-17 10:31:08 |
合計ジャッジ時間 | 46,488 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 1 TLE * 11 |
ソースコード
import Queue N = input() rinsetsu = [[] for i in xrange(N)] is_leaf = [True for i in xrange(N)] for _ in xrange(N-1): a, b = map(int, raw_input().split()) rinsetsu[a-1].append(b-1) rinsetsu[b-1].append(a-1) is_leaf[a-1] = False leaves = [i for i in xrange(N) if is_leaf[i]] ans = [float('inf') for i in xrange(N)] def bfs(start): visited = [False for i in xrange(N)] q = Queue.Queue() q.put((start, 0)) while not q.empty(): node, depth = q.get() if visited[node]: continue ans[node] = min(ans[node], depth) visited[node] = True for nn in rinsetsu[node]: if visited[nn]: continue q.put((nn, depth+1)) bfs(0) for leaf in leaves: bfs(leaf) for a in ans: print a