結果
問題 | No.2638 Initial fare |
ユーザー |
|
提出日時 | 2024-02-19 21:43:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 518 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 323,632 KB |
最終ジャッジ日時 | 2024-09-29 01:38:52 |
合計ジャッジ時間 | 6,205 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 TLE * 1 -- * 20 |
ソースコード
from collections import deque N=int(input()) G=[[] for _ in range(N)] for _ in range(N-1): u,v=list(map(int,input().split())) G[u-1].append(v-1) G[v-1].append(u-1) ans=0 for i in range(N): used=set() Q=deque() used.add(i) Q.append((i,0)) while Q: u,d=Q.popleft() if i!=u:ans+=1 if d==2: ans+=len(G[u])-1 continue for v in G[u]: if v in used:continue used.add(v) Q.append((v,d+1)) print(ans//2)