結果
問題 | No.994 ばらばらコイン |
ユーザー | toshiro_yanagi |
提出日時 | 2020-07-19 18:48:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 568 bytes |
コンパイル時間 | 570 ms |
コンパイル使用メモリ | 87,100 KB |
実行使用メモリ | 123,368 KB |
最終ジャッジ日時 | 2023-08-22 10:27:21 |
合計ジャッジ時間 | 10,275 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 526 ms
114,092 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 525 ms
109,176 KB |
testcase_09 | WA | - |
testcase_10 | AC | 527 ms
109,568 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 170 ms
80,876 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 171 ms
80,812 KB |
testcase_17 | AC | 167 ms
80,908 KB |
testcase_18 | AC | 168 ms
80,904 KB |
testcase_19 | AC | 169 ms
80,656 KB |
testcase_20 | AC | 170 ms
80,776 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
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]))