結果
| 問題 |
No.994 ばらばらコイン
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2020-03-19 20:08:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 648 bytes |
| コンパイル時間 | 1,725 ms |
| コンパイル使用メモリ | 176,004 KB |
| 実行使用メモリ | 9,456 KB |
| 最終ジャッジ日時 | 2024-12-14 03:27:50 |
| 合計ジャッジ時間 | 3,472 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void fin(T a){
cout<<a<<endl;
exit(0);
}
typedef pair<int,int> P;
signed main(){
int n,k;cin>>n>>k;
vector<int> edge[n];
for(int i=0;i<n-1;i++){
int u,v;cin>>u>>v;u--;v--;
edge[u].push_back(v);
edge[v].push_back(u);
}
if(n<k)fin(-1);
long long ans=0,cnt=0;
queue<P> que;
que.push(P(0,0));
vector<int> used(n,0);
while(cnt<k){
P p=que.front();que.pop();
ans+=p.second*(p.second+1)/2;
cnt++;
used[p.first]=1;
for(int q:edge[p.first]){
if(used[q])continue;
que.push(P(q,p.second+1));
}
}
cout<<ans<<endl;
}
cureskol