結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー soto800soto800
提出日時 2020-01-31 22:08:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 176,240 KB
実行使用メモリ 16,664 KB
最終ジャッジ日時 2023-10-17 09:58:02
合計ジャッジ時間 4,193 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 14 ms
4,944 KB
testcase_14 AC 13 ms
4,972 KB
testcase_15 AC 13 ms
4,968 KB
testcase_16 AC 14 ms
4,944 KB
testcase_17 AC 15 ms
5,508 KB
testcase_18 AC 47 ms
7,552 KB
testcase_19 AC 56 ms
9,260 KB
testcase_20 AC 104 ms
10,316 KB
testcase_21 AC 197 ms
13,024 KB
testcase_22 AC 269 ms
15,632 KB
testcase_23 AC 283 ms
16,664 KB
testcase_24 AC 225 ms
16,660 KB
testcase_25 AC 278 ms
16,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

map<lli,vector<lli>> d;
lli branch[100100];
lli data[100100];
bool allTwo;
void dfs(lli from){
	if(data[from])return;
	if(branch[from]<2){
		allTwo=false;
	}
	data[from]=1;
	for(auto e:d[from]){
		dfs(e);
	}
}

signed main(){

	lli n;
	cin>>n;
	lli two=0;
	lli one=0;
	lli zero;

	REP(i,0,n-1){
		lli u,v;
		cin>>u>>v;
		d[u].push_back(v);
		d[v].push_back(u);
		branch[u]++;
		branch[v]++;
	}

	REP(i,0,n){
		allTwo=true;
		if(data[i])continue;
		if(branch[i]==0){
			two++;
			continue;
		}
		dfs(i);
		if(allTwo)two++;
		else one++;
	}

	if(DEBUG)cout<<"one="<<one<<" two="<<two<<endl;

	if(one==0){
		if(two<=2)cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
	else if(one==1){
		if(two>0)cout<<"Alice"<<endl;
		else cout<<"Bob"<<endl;
	}
	else cout<<"Alice"<<endl;

	return 0;
}
0