結果
| 問題 | No.994 ばらばらコイン |
| コンテスト | |
| ユーザー |
r_ishida
|
| 提出日時 | 2026-02-08 05:56:36 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 163 ms / 2,000 ms |
| コード長 | 757 bytes |
| 記録 | |
| コンパイル時間 | 3,415 ms |
| コンパイル使用メモリ | 82,296 KB |
| 実行使用メモリ | 95,312 KB |
| 最終ジャッジ日時 | 2026-02-08 05:56:48 |
| 合計ジャッジ時間 | 7,748 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import math
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, k = MI()
x = {}
for i in range(n-1):
a, b = MI()
if a-1 in x:
x[a-1].append(b-1)
else:
x[a-1] = [b-1]
if b-1 in x:
x[b-1].append(a-1)
else:
x[b-1] = [a-1]
from collections import deque
d = deque()
s = [0]*n
d.append(0)
while d:
y = d.pop()
for i in x[y]:
if s[i] == 0:
s[i] = 1
d.append(i)
if sum(s) < k:
print(-1)
else:
print(k-1)
r_ishida