結果

問題 No.994 ばらばらコイン
ユーザー kzyKTkzyKT
提出日時 2020-02-21 21:24:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,460 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 163,784 KB
実行使用メモリ 17,732 KB
最終ジャッジ日時 2024-04-17 07:06:00
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

vector<ll> v[111111],a;

void dfs(int x,int p,int t) {
  a.pb(t);
  rep(i,v[x].size()) {
    int y=v[x][i];
    if(y!=p) dfs(y,x,t+1);
  }
}

void Main() {
  ll n,m;
  cin >> n >> m;
  rep(i,n-1) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  dfs(0,-1,0);
  sort(all(a));
  if(n<m) {
    pr(-1);
    return;
  }
  ll ans=0;
  rep(i,m) ans+=a[i];
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0