結果

問題 No.994 ばらばらコイン
ユーザー O2MTO2MT
提出日時 2021-02-27 18:49:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 537 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 89,672 KB
最終ジャッジ日時 2024-04-10 15:47:53
合計ジャッジ時間 3,081 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 37 ms
55,660 KB
testcase_02 AC 128 ms
88,684 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 135 ms
85,380 KB
testcase_09 WA -
testcase_10 AC 137 ms
85,596 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 37 ms
54,292 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 35 ms
54,236 KB
testcase_17 AC 34 ms
55,592 KB
testcase_18 AC 36 ms
54,784 KB
testcase_19 AC 34 ms
54,308 KB
testcase_20 AC 35 ms
54,528 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,K = map(int,input().split())
g = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
que = deque([(0,K,0,[0]*N)])
ans = 10**18
while que:
    node_f,coin,count,rec = que.pop()
    if coin == 1:
        ans = min(ans,count)
    for node_t in g[node_f]:
        if node_t == 0 or rec[node_t] == 0:
            rec[node_t] += 1
            que.append((node_t,coin-1,count+1,rec))
if ans == 10**18:
    ans = -1
print(ans)
0