結果

問題 No.994 ばらばらコイン
ユーザー plin92793134plin92793134
提出日時 2020-02-23 14:00:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 110,228 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-04-18 08:41:25
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 43 ms
18,816 KB
testcase_03 AC 55 ms
9,984 KB
testcase_04 AC 56 ms
9,984 KB
testcase_05 AC 27 ms
6,656 KB
testcase_06 AC 62 ms
10,112 KB
testcase_07 AC 61 ms
10,240 KB
testcase_08 AC 38 ms
7,936 KB
testcase_09 AC 58 ms
9,728 KB
testcase_10 AC 37 ms
7,808 KB
testcase_11 AC 47 ms
8,704 KB
testcase_12 AC 48 ms
9,088 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<vector<ll>>ed(n);
  rep(i,n-1){
    ll a,b;cin>>a>>b;
    a--;b--;
    ed[a].push_back(b);
    ed[b].push_back(a);

  }
  vector<ll>dist(n,-1);
  dist[0]=0;
  function<void(ll ,ll)>dfs=[&](ll no,ll pa){
    for(auto nn:ed[no]){
      if(nn==pa)continue;
      dist[nn]=dist[no]+1;
      dfs(nn,no);
    }
  };
  dfs(0,-1);
  sort(all(dist));
  if(k>n){
    cout<<-1<<endl;
    return 0;
  }

  cout<<k-1<<endl;

  return 0;

}
0