結果

問題 No.994 ばらばらコイン
ユーザー utouto97utouto97
提出日時 2020-02-21 21:32:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,058 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 171,636 KB
実行使用メモリ 10,048 KB
最終ジャッジ日時 2023-07-30 05:37:43
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 66 ms
8,836 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 53 ms
8,240 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
5,608 KB
testcase_17 AC 3 ms
5,648 KB
testcase_18 AC 3 ms
5,600 KB
testcase_19 AC 4 ms
5,632 KB
testcase_20 AC 3 ms
5,588 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  */

int n, k;
V<int> es[101010];
V<int> dist;

void dfs(int v, int p){
  for(int to : es[v]){
    if(to == p) continue;
    dist[to] = dist[v] + 1;
    dfs(to, v);
  }
}

signed main() {
  cin >> n >> k;
  rep(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    es[a].emplace_back(b);
    es[b].emplace_back(a);
  }

  if(k > n){
    cout << -1 << endl;
    return 0;
  }

  dist.resize(n);
  dfs(0, -1);
  sort(all(dist));

  int ans = 0;
  rep(i, 0, k) ans += dist[i];

  cout << ans << endl;

//  rep(i, 0, n) cout << dist[i] << " ";
//  cout << endl;

  return 0;
}
0