結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
54,900 KB
testcase_02 AC 142 ms
89,564 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 149 ms
86,240 KB
testcase_09 WA -
testcase_10 AC 153 ms
85,952 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 38 ms
54,072 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 38 ms
55,612 KB
testcase_17 AC 39 ms
54,076 KB
testcase_18 AC 39 ms
54,148 KB
testcase_19 AC 39 ms
54,748 KB
testcase_20 AC 38 ms
54,820 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def setPro(t,c,cnt,r,v):
    v[node_t] = True
    if r[node_t] == 0:
        r[node_t] += 1
        c -= 1
    return (node_t,c,cnt+1,r,v)

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)

summary = [0]*N
summary[0] = 1
que = deque([(0,K-1,0,summary,[False]*N)])
ans = 10**18

while que:
    node_f,coin,count,rec,visited = que.popleft()
    if coin == 0:
        ans = min(ans,count)
    elif coin < 0:
        continue
    for node_t in g[node_f]:
        if not visited[node_t]:
            que.append(setPro(node_t,coin,count,rec,visited))

if ans == 10**18:
    ans = -1

print(ans)
0