結果

問題 No.994 ばらばらコイン
ユーザー titia
提出日時 2020-02-21 21:27:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 465 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 29,212 KB
最終ジャッジ日時 2024-10-08 21:04:21
合計ジャッジ時間 4,007 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,K=map(int,input().split())

if K>N:
    print(-1)
    sys.exit()

E=[[] for i in range(N+1)]
ANS=[-1]*(N+1)

for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

from collections import deque

Q=deque()
Q.append(1)
ANS[1]=0
while Q:
    x=Q.popleft()
    for to in E[x]:
        if ANS[to]==-1:
            ANS[to]=ANS[x]+1
            Q.append(to)

ANS.sort()
print(sum(ANS[1:1+K]))
0