結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー satashunsatashun
提出日時 2020-01-31 21:42:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,957 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 177,680 KB
実行使用メモリ 4,412 KB
最終ジャッジ日時 2023-10-17 09:03:29
合計ジャッジ時間 3,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 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 7 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 32 ms
4,348 KB
testcase_21 AC 53 ms
4,412 KB
testcase_22 AC 66 ms
4,412 KB
testcase_23 AC 65 ms
4,412 KB
testcase_24 AC 63 ms
4,412 KB
testcase_25 AC 64 ms
4,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

class unionfind {
	vector<int> par, rank;

public:
	void init(int n) {
		par.resize(n);
		rank.resize(n);

		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return ;

		if (rank[x] < rank[y]) par[x] = y;
		else {
			par[y] = x;
			if (rank[x] == rank[y]) ++rank[x];
		}
	}

	bool same(int x, int y) { return (find(x) == find(y)); }
};

int main() {
	int N; cin >> N;
	unionfind uf;
	uf.init(N);
	V<int> deg(N);

	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		++deg[a]; ++deg[b];
		uf.unite(a, b);
	}

	map<int, int> T;
	rep(i, N) T[uf.find(i)]++;

	if (T.size() > 2) {
		puts("Alice");
	} else if (T.size() == 1) {
		puts("Bob");
	} else {
		bool one = 0;
		rep(i, N) if (deg[i] == 1) {
			one = 1;
		}
		puts(one ? "Alice" : "Bob");
	}

	return 0;
}
0