結果

問題 No.2638 Initial fare
ユーザー CecilCecil
提出日時 2024-02-19 22:16:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 666 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 50,144 KB
最終ジャッジ日時 2024-02-19 22:16:13
合計ジャッジ時間 4,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
16,916 KB
testcase_01 AC 27 ms
10,112 KB
testcase_02 AC 26 ms
10,112 KB
testcase_03 AC 31 ms
10,112 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 #

import sys
sys.setrecursionlimit(1 << 20)
N = int(input())
G = [ [] for _ in range(N+1) ]

for _ in range(N-1):
    u,v = map(int, input().split())
    G[u].append(v)
    G[v].append(u)
edges = set()

from collections import deque
def bfs(s):
    dist = [-1]*(N+1)
    dist[s] = 0
    que = deque()
    que.append(s)
    while que:
        v = que.popleft()
        for v2 in G[v]:
            if dist[v2] != -1 or dist[v2]>3:
                continue
            dist[v2] = dist[v]+1
            if dist[v2]-dist[s]<4:
                edges.add((min(v2,s),max(v2,s)))
            que.append(v2)
for i in range(1, N+1):
    bfs(i)
    #print(edges)
print(len(edges))
0