結果
| 問題 |
No.806 木を道に
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-22 22:21:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 839 bytes |
| コンパイル時間 | 158 ms |
| コンパイル使用メモリ | 82,516 KB |
| 実行使用メモリ | 92,528 KB |
| 最終ジャッジ日時 | 2024-09-19 05:53:26 |
| 合計ジャッジ時間 | 3,704 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 21 |
ソースコード
from collections import deque
N = int( input())
E = [ [] for _ in range(N)]
for _ in range(N-1):
a, b = map( int, input().split())
a, b = a-1, b-1
E[a].append(b)
E[b].append(a)
s = 0
V = [-1]*N
V[s] = 0
d = deque()
for t in E[s]:
d.append(t)
V[t] = 1
while d:
t = d.popleft()
l = V[t]
for u in E[t]:
if V[u] == -1:
V[u] = l+1
s = V.index( max(V))
V = [-1]*N
V[s] = 0
d = deque()
for t in E[s]:
d.append(t)
V[t] = 1
while d:
t = d.popleft()
l = V[t]
for u in E[t]:
if V[u] == -1:
V[u] = l+1
m = max(V)
g = V.index(m)
c = g
ans = 0
Z = [0]*N
Z[g] = 1
for i in range(m, 0, -1):
for t in E[c]:
if Z[t] == 1:
continue
if V[t] == i-1:
c = t
else:
ans += 1
Z[t] = 1
print(ans)