結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー snrnsidy
提出日時 2021-09-30 22:36:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 199,260 KB
最終ジャッジ日時 2025-01-24 18:43:55
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

vector <int> adj[100005];
int n,a,b;
bool visited[100005];
int cnt = 0;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;

	for(int i=0;i<n-1;i++)
	{
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	memset(visited,false,sizeof(visited));

	vector <int> vec;
	for(int i=0;i<n;i++)
	{
		int MIN = 1e9;
		if(visited[i]==false)
		{
			queue <int> que;
			cnt++;
			que.push(i);
			visited[i] = true;
			while(!que.empty())
			{
				int now = que.front();
				que.pop();
				MIN = min(MIN,(int)(adj[now].size()));
				for(auto next : adj[now])
				{
					if(visited[next]==false)
					{
						visited[next] = true;
						que.push(next);
					}
				}
			}
		}
		if(MIN==1)
		{
			vec.push_back(MIN);
		}
	}

	if(cnt==1) cout << "Bob" << '\n';
	else if(cnt==2)
	{
		if(vec.size()==0) cout << "Bob" << '\n';
		else cout << "Alice" << '\n';
	}
	else
	{
		cout << "Alice" << '\n';
	}

	return 0;
}
0