結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ndifixndifix
提出日時 2020-01-31 23:17:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,120 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 176,096 KB
実行使用メモリ 6,024 KB
最終ジャッジ日時 2023-10-17 12:29:19
合計ジャッジ時間 3,228 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 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 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 21 ms
4,476 KB
testcase_19 WA -
testcase_20 AC 34 ms
4,704 KB
testcase_21 AC 54 ms
5,496 KB
testcase_22 AC 68 ms
6,024 KB
testcase_23 WA -
testcase_24 AC 70 ms
5,760 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
template<class T>void sort(vector<T> &v){sort(v.begin(),v.end());}
template<class T>int lower_bound(vector<T> &v, T key){
	return distance(v.begin(), lower_bound(v.begin(),v.end(),key));
}
template<class T>int upper_bound(vector<T> &v, T key){
	return distance(v.begin(), upper_bound(v.begin(), v.end(), key));
}

vector<int> par;
int findpar(int i){
	if(par[i]==i)return i;
	else	return findpar(par[i]);
}

int main(){
	int n;cin>>n;
	vector<int> u(n-1),v(n-1);
	for(auto &i:u)cin>>i;
	for(auto &i:v)cin>>i;

	par.resize(n);for(int i=0;i<n;i++)par[i]=i;
	for(int i=0;i<n-1;i++){
		int a=min(u[i],v[i]), b=max(u[i],v[i]);
		if(par[a]<par[b]){par[b]=a;par[b]=findpar(b);par[a]=findpar(a);}
		if(par[a]>par[b]){par[a]=b;par[b]=findpar(b);par[a]=findpar(a);}
	}
	set<int> s;for(auto i:par)s.insert(i);
	if(s.size()>=3){cout<<"Alice"<<endl;return 0;}
	if(s.size()==1){cout<<"Bob"<<endl;return 0;}

	vector<int> w(n);
	for(int i=0;i<n-1;i++){
		w[u[i]]++;
		w[v[i]]++;
	}
	for(auto i:w)if(i==1){cout<<"Alice"<<endl;return 0;}
	cout<<"Bob"<<endl;
	return 0;
}
0