結果
問題 | No.994 ばらばらコイン |
ユーザー |
|
提出日時 | 2022-08-17 14:28:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 180 ms / 2,000 ms |
コード長 | 647 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 89,152 KB |
最終ジャッジ日時 | 2024-10-04 15:56:40 |
合計ジャッジ時間 | 3,146 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
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 if k == 1: print(0) exit() f = False cnt = 0 while f == False and len(d) > 0: 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 k == 1: f = True break #print(k) if f == True: print(cnt) else: print(-1)