結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 36 ms
55,340 KB
testcase_02 AC 125 ms
88,756 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 138 ms
85,352 KB
testcase_09 WA -
testcase_10 AC 116 ms
84,992 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 36 ms
54,488 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 36 ms
54,448 KB
testcase_17 AC 34 ms
54,432 KB
testcase_18 AC 35 ms
54,792 KB
testcase_19 AC 34 ms
54,632 KB
testcase_20 AC 35 ms
54,476 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)
visited = [0]*N
que = deque([(0,K,0)])
ans = -1
while que:
    node_f,coin,count = que.pop()
    if coin == 1:
        ans = count
        break
    for node_t in g[node_f]:
        if node_t == 0 or visited[node_t] == 0:
            visited[node_t] += 1
            que.append((node_t,coin-1,count+1))

print(ans)
0