結果
| 問題 |
No.994 ばらばらコイン
|
| コンテスト | |
| ユーザー |
ゆきのん
|
| 提出日時 | 2020-03-14 03:02:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,542 bytes |
| コンパイル時間 | 1,910 ms |
| コンパイル使用メモリ | 177,256 KB |
| 実行使用メモリ | 10,368 KB |
| 最終ジャッジ日時 | 2024-11-23 18:13:09 |
| 合計ジャッジ時間 | 4,384 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 15 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
vector<int> G[1<<17];
int main(){
int n,k;cin >> n >> k;
if(k > n) puts("-1");
else{
for (int i = 0; i < n-1; i++) {
int a,b;cin >> a >> b;
a--,b--;
G[a].pb(b);
G[b].pb(a);
}
if(k == 1) cout << 0 << endl;
else{
priority_queue<pair<int,P>> q;
k -= G[0].size() + 1;
int ans = 1;
for (int i = 0; i < G[0].size(); i++) {
q.push(mp(G[G[0][i]].size(), mp(G[0][i],0)));
}
while(k > 0){
auto p = q.top();q.pop();
k -= p.fs - 1;
ans++;
for(auto g:G[p.sc.fs]){
if(g == p.sc.sc) continue;
q.push(mp(G[g].size(), mp(g, p.sc.fs)));
}
}
cout << ans << endl;
}
}
return 0;
}
ゆきのん