結果
| 問題 |
No.2638 Initial fare
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:31:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 500 bytes |
| コンパイル時間 | 156 ms |
| コンパイル使用メモリ | 82,192 KB |
| 実行使用メモリ | 110,308 KB |
| 最終ジャッジ日時 | 2024-09-29 01:26:44 |
| 合計ジャッジ時間 | 5,373 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 TLE * 1 -- * 20 |
ソースコード
from collections import deque
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
u, v = map(int, input().split())
u -= 1
v -= 1
edge[u].append(v)
edge[v].append(u)
ans = 0
nxt = deque()
used = [False] * N
used[0] = True
nxt.append(0)
while nxt:
pos = nxt.pop()
for to in edge[pos]:
ans += 1
for nt in edge[to]:
if nt != pos : ans += len(edge[nt])
if not used[to] : nxt.append(to); used[to] = True
print(ans // 2)