結果
| 問題 | No.1098 LCAs |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-20 22:34:57 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 453 ms / 2,000 ms |
| コード長 | 563 bytes |
| 記録 | |
| コンパイル時間 | 443 ms |
| コンパイル使用メモリ | 85,152 KB |
| 実行使用メモリ | 127,360 KB |
| 最終ジャッジ日時 | 2026-05-20 22:35:06 |
| 合計ジャッジ時間 | 8,311 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
from collections import deque
n=int(input())
v=[[] for i in range(n)]
for i in range(n-1):
a,b=map(int,input().split());a-=1;b-=1
v[a].append(b);v[b].append(a)
f=deque([(0,0,0)])
ans=[0]*n
dep=[1]*n
while f:
q,w,e=f.pop()
if len(v[q])>e:
f.append((q,w,e+1))
if v[q][e]!=w:
f.append((v[q][e],q,0))
else:
dp=[1,0]
for i in v[q]:
if i==w:
continue
dp[1]+=dp[0]*dep[i];dp[0]+=dep[i]
dep[q]+=dep[i]
ans[q]=dp[1]*2+1
for i in ans:
print(i)