結果
| 問題 |
No.994 ばらばらコイン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-21 22:23:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 827 bytes |
| コンパイル時間 | 2,136 ms |
| コンパイル使用メモリ | 177,280 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2024-10-08 21:55:28 |
| 合計ジャッジ時間 | 3,572 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
int main() {
int n, k;
cin >> n >> k;
if(n < k) cout << -1 << endl;
else {
vector<vector<int>> G(n);
rep(i, n-1) {
int a, b;
cin >> a >> b;
a--;b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
queue<pair<int, int>> que;
long long total = 0LL;
que.emplace(make_pair(0, -1));
vector<int> used(n);
int num = 0;
while(!que.empty()) {
pair<int, int> p = que.front();que.pop();
used[p.first] = 1;
total += (long long)(p.second + 1);
num++;
if(num == k) break;
for(auto next_v : G[p.first]) {
if(used[next_v]) continue;
que.emplace(make_pair(next_v, p.second+1));
}
}
cout << total << endl;
}
}