結果

問題 No.994 ばらばらコイン
ユーザー ゆきのんゆきのん
提出日時 2020-03-14 03:02:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,542 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 174,564 KB
実行使用メモリ 10,488 KB
最終ジャッジ日時 2023-08-15 11:26:06
合計ジャッジ時間 4,373 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
6,404 KB
testcase_02 AC 4 ms
6,336 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
6,392 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
6,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 4 ms
6,420 KB
testcase_17 WA -
testcase_18 AC 4 ms
6,340 KB
testcase_19 AC 4 ms
6,388 KB
testcase_20 AC 3 ms
6,324 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0