結果
| 問題 |
No.2638 Initial fare
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:38:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 476 bytes |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 82,372 KB |
| 実行使用メモリ | 317,108 KB |
| 最終ジャッジ日時 | 2024-09-29 01:34:53 |
| 合計ジャッジ時間 | 6,299 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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==3:continue
for v in G[u]:
if v in used:continue
used.add(v)
Q.append((v,d+1))
print(ans//2)