結果

問題 No.994 ばらばらコイン
ユーザー O2MTO2MT
提出日時 2021-02-27 19:36:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 711 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 90,304 KB
最終ジャッジ日時 2024-04-10 15:48:56
合計ジャッジ時間 3,592 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 38 ms
54,528 KB
testcase_02 AC 139 ms
89,592 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 157 ms
85,940 KB
testcase_09 WA -
testcase_10 AC 164 ms
85,796 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 39 ms
54,424 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 38 ms
54,792 KB
testcase_17 AC 39 ms
54,212 KB
testcase_18 AC 39 ms
53,940 KB
testcase_19 AC 38 ms
53,544 KB
testcase_20 AC 39 ms
54,488 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)

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)
    for node_t in g[node_f]:
        if not visited[node_t]:
            c = coin
            visited[node_t] = True
            if rec[node_t] == 0:
                rec[node_t] += 1
                c -= 1
            que.append((node_t,c,count+1,rec,visited))

if ans == 10**18:
    ans = -1
    
print(ans)
0