結果

問題 No.994 ばらばらコイン
ユーザー stngstng
提出日時 2022-08-17 14:22:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 563 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 89,200 KB
最終ジャッジ日時 2024-04-15 04:30:12
合計ジャッジ時間 3,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
54,060 KB
testcase_01 AC 39 ms
54,460 KB
testcase_02 AC 136 ms
88,552 KB
testcase_03 AC 155 ms
88,988 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 190 ms
89,148 KB
testcase_07 WA -
testcase_08 AC 144 ms
85,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 156 ms
85,612 KB
testcase_12 WA -
testcase_13 AC 37 ms
54,500 KB
testcase_14 AC 38 ms
54,316 KB
testcase_15 AC 38 ms
54,020 KB
testcase_16 AC 38 ms
55,692 KB
testcase_17 AC 37 ms
55,032 KB
testcase_18 AC 38 ms
54,240 KB
testcase_19 AC 37 ms
54,080 KB
testcase_20 AC 36 ms
53,776 KB
testcase_21 AC 38 ms
53,856 KB
testcase_22 AC 37 ms
55,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,k = map(int,input().split())

ab = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ab[a].append(b)
    ab[b].append(a)

d = deque()
d.append([0,0])
chk = [0]*(n)
chk[0] = 1

f = False
cnt = 0

while len(d) > 0:
    if k == 1:
        f = True
        break
    tmp,num = d.popleft()
    for i in ab[tmp]:
        if chk[i] == 0:
            chk[i] = 1
            d.append([i,num+1])
            k -= 1
            cnt += 1

if f == True:
    print(cnt)
else:
    print(-1)
0