結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー set0gut1set0gut1
提出日時 2020-01-31 21:34:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 96,160 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2024-09-17 07:19:36
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

ll union_find_find(ll node, vector<ll> &vec) {
  if (vec[node] == -1)
    return node;
  ll ret = union_find_find(vec[node], vec);
  vec[node] = ret;
  return ret;
}

void union_find_union(ll a, ll b, vector<ll> &vec) {
  ll a_root = union_find_find(a, vec);
  ll b_root = union_find_find(b, vec);
  if (a_root != b_root)
    vec[b_root] = a_root;
}

void solve() {
  ll N;
  cin >> N;
  vector<ll> uf(N, -1);
  unordered_map<ll, ll> edges;
  rep (i, N-1) {
    ll u, v;
    cin >> u >> v;
    union_find_union(u, v, uf);
    edges[u]++;
    edges[v]++;
  }
  unordered_map<ll, ll> st;
  rep (i, N) st[union_find_find(i, uf)]++;

  if (st.size() == 1) cout << "Bob" << endl;
  else if (st.size() > 2) cout << "Alice" << endl;
  else {
    bool tmp = false;
    for (auto it: edges) if (it.second == 1) tmp = true;
    if (tmp) cout << "Alice" << endl;
    else cout << "Bob" << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}
0