結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tko919tko919
提出日時 2020-01-31 21:41:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,913 bytes
コンパイル時間 1,737 ms
コンパイル使用メモリ 178,916 KB
実行使用メモリ 813,732 KB
最終ジャッジ日時 2023-10-17 09:01:45
合計ジャッジ時間 4,395 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,516 KB
testcase_01 AC 3 ms
8,520 KB
testcase_02 AC 3 ms
8,520 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<class Abel> struct UnionFind {
	vector<int> par,rank;
	vector<Abel> diff_weight;
	UnionFind(int n=1,Abel SUM_UNITY=0){init(n, SUM_UNITY);}
	void init(int n=1,Abel SUM_UNITY=0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		rep(i,0,n)par[i]=-1,rank[i]=0,diff_weight[i]=SUM_UNITY;
	}
	int root(int x){
		if(par[x]<0)return x;
		int r=root(par[x]); diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
	}
	int size(int x){ return -par[root(x)]; }
	Abel weight(int x){root(x); return diff_weight[x];}
	bool issame(int x, int y){return root(x)==root(y);}
	bool merge(int x,int y,Abel w){
		w+=weight(x)-weight(y); x=root(x); y=root(y);
		if(x==y)return false;
		if(rank[x]<rank[y])swap(x,y),w=-w;
		if(rank[x]==rank[y])++rank[x];
		par[x]+=par[y]; par[y]=x; diff_weight[y]=w; return true;
	}
	Abel diff(int x,int y){return weight(y)-weight(x);}
};

set<int> g[101000];
bool f=0;
void dfs(int v,int p=-1){
	if(v==0&&p!=-1){f=1; return;}
	for(int to:g[v])if(to==0||to!=p)dfs(to,v);
}

int main(){
   int n; scanf("%d",&n);
   UnionFind<int> uni(n);
   rep(i,0,n-1){
	   int u,v; scanf("%d%d",&u,&v);
	   g[u].insert(v);
	   g[v].insert(u);
	   uni.merge(u,v,1);
   }
   set<int> rts;
   rep(i,0,n)rts.insert(uni.root(i));
   if(rts.size()==1)f=1;
   dfs(0);
   printf(f?"Bob\n":"Alice\n");
   return 0;
}
0