結果

問題 No.994 ばらばらコイン
ユーザー KKT89KKT89
提出日時 2020-02-21 21:34:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 843 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 83,188 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-17 07:28:32
合計ジャッジ時間 1,588 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
int d[100100];
vector<int> g[100100];
void dfs(int s,int p){
    for(int t:g[s]){
        if(t!=p){
            d[t]=d[s]+1;
            dfs(t,s);
        }
    }
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    if(n<k){
        cout << -1 << endl;
        return 0;
    }
    cout << k-1 << endl;
    return 0;
    for(int i=0;i<n-1;i++){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    d[0]=0;
    dfs(0,-1);
    vector<int> a(n);
    for(int i=0;i<n;i++){
        a[i]=d[i];
    }
    sort(a.begin(),a.end());
    ll ans=0;
    for(int i=0;i<k;i++){
        ans+=a[i];
    }
    cout << ans << endl;
}
0