結果
| 問題 | No.2638 Initial fare |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-05-25 07:50:13 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 926 bytes |
| 記録 | |
| コンパイル時間 | 143 ms |
| コンパイル使用メモリ | 85,504 KB |
| 実行使用メモリ | 1,346,108 KB |
| 最終ジャッジ日時 | 2026-05-25 07:50:32 |
| 合計ジャッジ時間 | 4,516 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 MLE * 2 -- * 22 |
ソースコード
from collections import defaultdict, deque
N = int(input())
degs = [0] * N
adj = defaultdict(list)
for _ in range(N-1):
U, V = map(lambda x: int(x)-1, input().split())
adj[U].append(V)
adj[V].append(U)
degs[U] += 1
degs[V] += 1
leaves = []
for i in range(N):
if degs[i] == 1:
leaves.append(i)
def f(w):
q = deque()
for v in leaves:
q.append(deque([v]))
used = set()
while q:
d = q.popleft()
hd = d[0]
tl = d[-1]
# print(f'{d=} {hd=} {tl=}')
if len(d) == w:
mi = min(hd, tl)
ma = max(hd, tl)
used.add((mi, ma))
for to in adj[tl]:
if len(d) > 1 and d[-2] == to: continue
d2 = d.copy()
d2.append(to)
if len(d2) > w:
d2.popleft()
q.append(d2)
return len(used)
ans = f(2) + f(3) + f(4)
print(ans)
norioc