結果

問題 No.994 ばらばらコイン
ユーザー madokamadoka
提出日時 2020-02-21 22:40:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 104,456 KB
実行使用メモリ 20,916 KB
最終ジャッジ日時 2024-04-17 07:51:11
合計ジャッジ時間 2,600 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,132 KB
testcase_01 AC 3 ms
8,324 KB
testcase_02 AC 81 ms
20,712 KB
testcase_03 AC 77 ms
12,228 KB
testcase_04 AC 76 ms
11,484 KB
testcase_05 AC 39 ms
10,680 KB
testcase_06 AC 92 ms
20,916 KB
testcase_07 AC 79 ms
12,356 KB
testcase_08 AC 62 ms
16,888 KB
testcase_09 AC 73 ms
11,972 KB
testcase_10 AC 53 ms
10,580 KB
testcase_11 AC 73 ms
17,776 KB
testcase_12 AC 69 ms
12,916 KB
testcase_13 AC 4 ms
8,304 KB
testcase_14 AC 3 ms
8,216 KB
testcase_15 AC 3 ms
8,332 KB
testcase_16 AC 4 ms
8,284 KB
testcase_17 AC 4 ms
8,128 KB
testcase_18 AC 4 ms
8,168 KB
testcase_19 AC 4 ms
8,260 KB
testcase_20 AC 4 ms
8,144 KB
testcase_21 AC 4 ms
8,248 KB
testcase_22 AC 4 ms
8,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<int> g[200020];
int s[200020];
bool used[200020];
int cnt;
int k;
queue<int> que;

void dfs(int x){
	used[x]=1;
	
	if(k<2){
		return;
	}
	
	for(auto y:g[x]){
		if(used[y]) continue;
		k--;
		cnt++;
		if(k<2){
			return;
		}
		que.push(y);
	}
	while(!que.empty()){
		int p = que.front();
		que.pop();
		dfs(p);
	}	

}
int main()
{
	cnt=0;
	cin>>n>>k;
	for(int i=0; i<n-1; i++){
		int a, b; cin>>a>>b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0);
	if(k>=2){
		printf("-1");
	}
	else{
		printf("%d",cnt);
	}
	return 0;
}
0