結果
| 問題 |
No.994 ばらばらコイン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-14 18:41:38 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,029 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 41,368 KB |
| 最終ジャッジ日時 | 2024-11-23 21:22:48 |
| 合計ジャッジ時間 | 5,934 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 6 |
ソースコード
class NTree(object):
def __init__(self):
self.count = 0
def constructor(self,N, K, edges, num):
self.N = int(N)
self.K = int(K)
self.edges = edges
self.num = num
if self.N < self.K:
print(-1)
exit()
def run(self):
sorted_num = dict(sorted(self.num.items(), key=lambda x:x[0]))
K = self.K
for key, value in sorted_num.items():
if value >= K:
self.count += K
break
else:
self.count += value
K = K - value
print(self.count-1)
if __name__=="__main__":
N, K = input().split(" ")
edges= list()
num = dict()
for i in range(1, int(N)):
edge = list(map(int, input().split(" ")))
edges.append(edge)
if not edge[0] in num.keys():
num[edge[0]] = 1
else:
num[edge[0]] += 1
func = NTree()
func.constructor(N=N, K=K, edges=edges, num=num)
func.run()