結果
問題 | No.2638 Initial fare |
ユーザー | pirosiki197 |
提出日時 | 2024-02-20 00:48:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 588 bytes |
コンパイル時間 | 593 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 266,784 KB |
最終ジャッジ日時 | 2024-02-20 00:48:08 |
合計ジャッジ時間 | 4,637 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge16 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
55,616 KB |
testcase_01 | AC | 38 ms
55,616 KB |
testcase_02 | AC | 39 ms
53,460 KB |
testcase_03 | AC | 50 ms
63,912 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
from collections import deque n = int(input()) rosen = [[] for _ in range(n+1)] for i in range(n-1): a, b = map(int, input().split()) rosen[a].append(b) rosen[b].append(a) ans = 0 def bfs(start): global ans queue = deque([start]) d = [-1] * (n+1) d[start] = 0 while queue: v = queue.popleft() for i in rosen[v]: if d[i] != -1 or d[v] > 2: continue d[i] = d[v] + 1 if d[i] <= 3: ans += 1 queue.append(i) for i in range(1, n+1): bfs(i) print(ans // 2)