結果

問題 No.994 ばらばらコイン
ユーザー CleyLCleyL
提出日時 2020-02-21 21:32:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 76,884 KB
実行使用メモリ 9,184 KB
最終ジャッジ日時 2023-07-30 05:38:34
合計ジャッジ時間 2,527 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 66 ms
8,868 KB
testcase_03 AC 74 ms
9,064 KB
testcase_04 AC 70 ms
8,916 KB
testcase_05 AC 35 ms
6,204 KB
testcase_06 AC 74 ms
9,184 KB
testcase_07 AC 71 ms
8,884 KB
testcase_08 AC 50 ms
7,300 KB
testcase_09 AC 68 ms
8,820 KB
testcase_10 AC 50 ms
7,216 KB
testcase_11 AC 58 ms
7,868 KB
testcase_12 AC 61 ms
8,148 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct dta{
  int nm;
  int nw;

};
bool lck[100000];
int main(){
  int n,k;cin>>n>>k;k--;
  if(!k){
    cout << 0 << endl;
    return 0;
  }
  vector<int> nya[n];
  for(int i = 0; n-1 > i; i++){
    int a,b;cin>>a>>b;a--;b--;
    nya[a].push_back(b);
    nya[b].push_back(a);
  }
  queue<dta> A;
  A.push({0,0});
  lck[0] = true;
  int ans = 0;
  while(!A.empty()){
    dta Z = A.front();A.pop();
    for(int i = 0; nya[Z.nm].size() > i; i++){
      if(!lck[nya[Z.nm][i]]){
        A.push({nya[Z.nm][i],Z.nw+1});
        //cout << "!!" << Z.nm << " " << nya[Z.nm][i] << endl;
        k--;
        ans++;
        lck[nya[Z.nm][i]] = true;
        if(!k){
          cout << ans << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  
}
0