結果

問題 No.994 ばらばらコイン
ユーザー brthyyjpbrthyyjp
提出日時 2020-02-21 21:57:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 637 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 88,704 KB
最終ジャッジ日時 2024-04-17 07:36:42
合計ジャッジ時間 3,093 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,504 KB
testcase_01 AC 45 ms
53,760 KB
testcase_02 AC 102 ms
84,480 KB
testcase_03 AC 140 ms
85,760 KB
testcase_04 AC 126 ms
85,632 KB
testcase_05 AC 99 ms
80,128 KB
testcase_06 AC 160 ms
88,704 KB
testcase_07 AC 121 ms
85,504 KB
testcase_08 AC 96 ms
79,872 KB
testcase_09 AC 126 ms
85,248 KB
testcase_10 AC 116 ms
83,968 KB
testcase_11 AC 140 ms
84,736 KB
testcase_12 AC 132 ms
85,120 KB
testcase_13 AC 45 ms
53,504 KB
testcase_14 AC 44 ms
53,376 KB
testcase_15 AC 45 ms
53,632 KB
testcase_16 AC 40 ms
51,968 KB
testcase_17 AC 45 ms
53,632 KB
testcase_18 AC 39 ms
51,968 KB
testcase_19 WA -
testcase_20 AC 40 ms
51,712 KB
testcase_21 AC 46 ms
53,504 KB
testcase_22 AC 46 ms
53,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

n, k = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
#print(g)

if k > n:
    print(-1)
    exit()

from collections import deque
q = deque()
q.append(0)
visit = [0]*n
cnt = 0
visit[0] = 1
while q:
    x = q.popleft()
    for new_x in g[x]:
        if visit[new_x] == 0:
            cnt += 1
            visit[new_x] = 1
            q.append(new_x)
        if cnt == k-1:
            print(sum(visit)-1)
            #print(visit)
            exit()
#print(cnt)
#print(visit)
0