結果
問題 | No.2427 Tree Distance Two |
ユーザー |
|
提出日時 | 2023-08-18 21:37:09 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 403 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 370,288 KB |
最終ジャッジ日時 | 2024-11-28 06:04:50 |
合計ジャッジ時間 | 63,748 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 20 |
ソースコード
from collections import deque n=int(input()) E=[[] for _ in range(n+1)] for _ in range(n-1): a,b=map(int,input().split()) E[a].append(b) E[b].append(a) for i in range(1,n+1): D=[10**6]*(n+1) D[i]=0 q=deque([i]) ans=0 while q: x=q.popleft() for e in E[x]: if D[x]+1<D[e]: D[e]=D[x]+1 if D[e]==2:ans+=1 if D[e]<2: q.append(e) print(ans)