結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー kotatsugamekotatsugame
提出日時 2020-02-02 03:33:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 70,388 KB
実行使用メモリ 4,416 KB
最終ジャッジ日時 2023-10-19 00:34:36
合計ジャッジ時間 2,014 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 46 ms
4,348 KB
testcase_22 AC 61 ms
4,416 KB
testcase_23 AC 63 ms
4,416 KB
testcase_24 AC 62 ms
4,416 KB
testcase_25 AC 63 ms
4,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N;
int sz[1<<17];
main()
{
	cin>>N;
	int cnt=N-1;
	UF uf(N);
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;
		cnt-=uf.unite(u,v);
		sz[u]++;sz[v]++;
	}
	if(cnt==0)cout<<"Bob"<<endl;
	else
	{
		int now=0;
		for(int i=0;i<N;i++)now+=sz[i]!=2;
		cout<<(cnt==1&&now==1?"Bob":"Alice")<<endl;
	}
}
0