結果
| 問題 |
No.277 根掘り葉掘り
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-04 23:39:13 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 493 bytes |
| コンパイル時間 | 46 ms |
| コンパイル使用メモリ | 6,784 KB |
| 実行使用メモリ | 22,016 KB |
| 最終ジャッジ日時 | 2024-07-19 02:25:22 |
| 合計ジャッジ時間 | 5,529 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 12 |
ソースコード
import sys
sys.setrecursionlimit(1000000)
def dfs(i, d):
R[i] = d
if len(chil[i]) > 0:
mn = 1e9
for j in chil[i]:
mn = min(mn, dfs(j, d + 1))
L[i] = mn
else:
L[i] = 0
return L[i] + 1
N = int(raw_input())
chil = [[] for i in xrange(N)]
for loop in xrange(N - 1):
x, y = map(int, raw_input().split())
x -= 1
y -= 1
chil[x].append(y)
R, L = [0] * N, [1e9] * N
dfs(0, 0)
for i in xrange(N):
print min(R[i], L[i])