結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー eQeeQe
提出日時 2020-04-29 23:41:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 170,092 KB
実行使用メモリ 11,220 KB
最終ジャッジ日時 2024-05-07 14:16:42
合計ジャッジ時間 2,743 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 10 ms
6,944 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 9 ms
6,940 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 23 ms
7,168 KB
testcase_19 AC 23 ms
7,168 KB
testcase_20 AC 37 ms
7,936 KB
testcase_21 AC 64 ms
9,472 KB
testcase_22 AC 74 ms
10,368 KB
testcase_23 AC 78 ms
11,216 KB
testcase_24 AC 73 ms
11,088 KB
testcase_25 AC 77 ms
11,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

class unionFind {
public:
  vector<ll> data;
  
  unionFind(ll size) {
    data.assign(size, -1);
  }
  
  bool same(ll x, ll y) {
    return find(x)==find(y);
  }
  
  void unite(ll x, ll y) {
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(data[x]>data[y]) swap(x, y);
    data[x]+=data[y];
    data[y]=x;
  }
  
  ll find(ll k) {
    if(data[k]<0) return k;
    return data[k]=find(data[k]);
  }
  
  ll size(ll k) {
    return -data[find(k)];
  }
  
};


int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  vector<ll> g[MAX];
  
  unionFind uf=unionFind(N);
  for(i=0; i<N-1; i++) {
    ll u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    uf.unite(u, v);
  }
  
  map<ll, vector<ll>> mp;
  for(i=0; i<N; i++) mp[uf.find(i)].push_back(i);
  
  if(mp.size()==1) {
    pt("Bob");
  }else if(mp.size()==2) {
    
    for(i=0; i<N; i++) {
      if(g[i].size()!=0&&g[i].size()!=2) {
        pt("Alice");
        return 0;
      }
    }
    
    pt("Bob");
    
  }else {
    pt("Alice");
  }
    
  
  
  
}
 
 
0