結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tko919tko919
提出日時 2020-01-31 21:33:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,715 bytes
コンパイル時間 1,737 ms
コンパイル使用メモリ 177,584 KB
実行使用メモリ 4,652 KB
最終ジャッジ日時 2023-10-17 08:50:03
合計ジャッジ時間 2,895 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 14 ms
4,348 KB
testcase_21 AC 24 ms
4,388 KB
testcase_22 AC 28 ms
4,388 KB
testcase_23 AC 28 ms
4,652 KB
testcase_24 AC 27 ms
4,652 KB
testcase_25 AC 27 ms
4,652 KB
権限があれば一括ダウンロードができます

ソースコード

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);}
};

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