結果

問題 No.994 ばらばらコイン
ユーザー kohei2019kohei2019
提出日時 2021-02-03 21:04:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 651 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 96,932 KB
最終ジャッジ日時 2023-09-12 16:47:12
合計ジャッジ時間 6,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,564 KB
testcase_01 AC 91 ms
71,680 KB
testcase_02 RE -
testcase_03 AC 253 ms
91,252 KB
testcase_04 AC 263 ms
91,240 KB
testcase_05 AC 182 ms
84,816 KB
testcase_06 AC 258 ms
91,472 KB
testcase_07 AC 257 ms
91,500 KB
testcase_08 AC 209 ms
87,412 KB
testcase_09 AC 238 ms
90,352 KB
testcase_10 AC 209 ms
87,452 KB
testcase_11 AC 217 ms
88,140 KB
testcase_12 AC 230 ms
89,340 KB
testcase_13 AC 89 ms
71,444 KB
testcase_14 AC 90 ms
71,824 KB
testcase_15 AC 91 ms
71,808 KB
testcase_16 AC 90 ms
71,564 KB
testcase_17 AC 90 ms
71,676 KB
testcase_18 AC 90 ms
71,692 KB
testcase_19 AC 90 ms
71,432 KB
testcase_20 AC 93 ms
71,748 KB
testcase_21 AC 92 ms
71,600 KB
testcase_22 AC 90 ms
71,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,K = map(int,input().split())
lsg = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    lsg[a].append(b)
    lsg[b].append(a)
#できるかどうかの判定が必要
depth = [-1]*(N)
depth[0] = 0
d = collections.deque()
d.append(0)
while d:
    v = d.pop()
    for j in lsg[v]:
        if depth[j] >= 0:
            continue
        depth[j] = depth[v]+1
        d.append(j)
lsc = [-1]*(N)
def dfs(k):
    cnt = 1
    for j in lsg[k]:
        if depth[j] < depth[k]:
            continue
        cnt += dfs(j)
    lsc[k] = cnt
    return cnt
dfs(0)

print(-1 if N < K else K-1)
0