結果

問題 No.994 ばらばらコイン
ユーザー RiburaRibura
提出日時 2020-05-01 01:25:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 748 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 22,548 KB
最終ジャッジ日時 2023-08-23 08:07:56
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 19 ms
8,552 KB
testcase_02 AC 196 ms
22,548 KB
testcase_03 AC 169 ms
21,324 KB
testcase_04 AC 165 ms
21,232 KB
testcase_05 AC 94 ms
14,784 KB
testcase_06 WA -
testcase_07 AC 167 ms
21,308 KB
testcase_08 AC 157 ms
17,180 KB
testcase_09 AC 155 ms
20,372 KB
testcase_10 AC 116 ms
17,400 KB
testcase_11 AC 177 ms
18,304 KB
testcase_12 AC 154 ms
19,072 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 19 ms
8,540 KB
testcase_17 AC 19 ms
8,664 KB
testcase_18 AC 20 ms
8,448 KB
testcase_19 AC 19 ms
8,608 KB
testcase_20 AC 19 ms
8,604 KB
testcase_21 AC 20 ms
8,468 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

n, k = map(int, readline().split())
graph = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, readline().split())
    graph[a - 1].append(b - 1)


def dfs(s):
    global k
    cnt = -1
    check = [False] * n
    stack = deque([s])
    while stack:
        now = stack.pop()
        check[now] = True
        for next in graph[now]:
            if check[next]:
                continue
            k -= 1
            cnt += 1
            if k == 0:
                print(cnt)
                exit()
            stack.appendleft(next)


dfs(0)
print(-1)
0