結果
| 問題 | No.994 ばらばらコイン |
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2020-03-19 20:07:22 |
| 言語 | C++14 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 664 bytes |
| 記録 | |
| コンパイル時間 | 986 ms |
| コンパイル使用メモリ | 192,280 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2026-10-12 02:31:35 |
| 合計ジャッジ時間 | 2,759 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
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);
int 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