結果

問題 No.994 ばらばらコイン
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2020-07-19 18:48:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 568 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 43,288 KB
最終ジャッジ日時 2023-08-22 10:27:09
合計ジャッジ時間 13,929 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1,121 ms
42,164 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 890 ms
32,384 KB
testcase_09 WA -
testcase_10 AC 903 ms
32,456 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 23 ms
9,044 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 23 ms
8,968 KB
testcase_17 AC 23 ms
9,024 KB
testcase_18 AC 23 ms
9,044 KB
testcase_19 AC 23 ms
9,136 KB
testcase_20 AC 23 ms
9,044 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
from collections import namedtuple
from sys import maxsize as inf
P = namedtuple("P", "i c")

n, k = map(int, input().split())
path = []
cst = []

for i in range(n):
    path.append(set())
    cst.append(inf)

for _ in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    path[a] |= {b}
    path[b] |= {a}

q = queue.Queue()
q.put(P(1, 0))
while q.qsize() != 0:
    p = q.get()
    if cst[p.i] <= p.c: continue
    cst[p.i] = p.c
    for j in path[p.i]:
        q.put(P(j, p.c + 1))

cst.sort()
if n < k: print(-1)
else: print(sum(cst[:k]))
0