結果
| 問題 | No.2638 Initial fare |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-05-25 08:00:48 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 814 bytes |
| 記録 | |
| コンパイル時間 | 135 ms |
| コンパイル使用メモリ | 85,236 KB |
| 実行使用メモリ | 158,164 KB |
| 最終ジャッジ日時 | 2026-05-25 08:01:14 |
| 合計ジャッジ時間 | 4,360 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 23 |
ソースコード
from collections import defaultdict, deque
import sys
sys.setrecursionlimit(10**6)
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):
used = set()
def dfs(vs):
hd = vs[0]
tl = vs[-1]
mi = min(hd, tl)
ma = max(hd, tl)
if mi != -1:
used.add((mi, ma))
for to in adj[tl]:
if to == vs[-2]: continue
xs = vs[1:] + [to]
dfs(xs)
for v in leaves:
vs = [-1] * w
vs[-1] = v
dfs(vs)
return len(used)
ans = f(2) + f(3) + f(4)
print(ans)
norioc