結果

問題 No.2638 Initial fare
ユーザー pirosiki197pirosiki197
提出日時 2024-02-20 00:38:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 672 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 291,448 KB
最終ジャッジ日時 2024-02-20 00:38:49
合計ジャッジ時間 4,587 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,616 KB
testcase_01 AC 38 ms
55,616 KB
testcase_02 AC 39 ms
55,616 KB
testcase_03 AC 48 ms
64,040 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = set()

def bfs(start):
    queue = deque([start])
    d = [-1] * (n+1)
    d[start] = 0
    while queue:
        v = queue.popleft()
        for i in rosen[v]:
            if d[i] != -1:
                continue
            d[i] = d[v] + 1
            if d[i] <= 3:
                if start < i:
                    ans.add((start, i))
                else:
                    ans.add((i, start))
                queue.append(i)

for i in range(1, n+1):
    bfs(i)
print(len(ans))
0