結果

問題 No.994 ばらばらコイン
ユーザー CleyLCleyL
提出日時 2020-02-21 21:32:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 77,476 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-04-17 07:26:31
合計ジャッジ時間 2,526 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 73 ms
9,216 KB
testcase_03 AC 84 ms
9,216 KB
testcase_04 AC 82 ms
9,216 KB
testcase_05 AC 41 ms
6,400 KB
testcase_06 AC 84 ms
9,344 KB
testcase_07 AC 81 ms
9,088 KB
testcase_08 AC 57 ms
7,424 KB
testcase_09 AC 76 ms
8,960 KB
testcase_10 AC 55 ms
7,424 KB
testcase_11 AC 69 ms
7,936 KB
testcase_12 AC 70 ms
8,448 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 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,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--;
  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