結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー toto6114
提出日時 2020-02-03 15:39:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 1,417 ms
コンパイル使用メモリ 109,984 KB
最終ジャッジ日時 2025-01-08 21:58:31
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int mod=998244353;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<ll,ll> P;
int par[100005]={},u,v,n,f=1;
int find(int x) {
  if(par[x]==x) {
    return x;
  }
  return par[x]=find(par[x]);
}
bool same(int x,int y) {
  return par[x]==par[y];
}
void unit(int x,int y) {
  x=find(x),y=find(y);
  if(x!=y) {
    par[x]=y;
  }
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> G[n]={};
  for(int i=0; i<n; i++) {
    par[i]=i;
  }
  for(int i=0; i<n-1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
    unit(u,v);
  }
  set<int> s;
  for(int i=0; i<n; i++) {
    s.insert(find(i));
  }
  if(s.size()==1) {
    cout << "Bob" << endl;
  }
  else if(s.size()>=3) {
    cout << "Alice" << endl;
  }
  else {
    for(int i=0; i<n; i++) {
      if(G[i].size()!=0&&G[i].size()!=2) {
        f=0;
      }
    }
    cout << (f?"Bob":"Alice") << endl;
  }
}
0