結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー set0gut1set0gut1
提出日時 2020-01-31 21:34:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 96,184 KB
実行使用メモリ 8,780 KB
最終ジャッジ日時 2023-10-17 08:51:47
合計ジャッジ時間 2,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 5 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 13 ms
4,856 KB
testcase_19 AC 13 ms
4,856 KB
testcase_20 AC 22 ms
6,056 KB
testcase_21 AC 35 ms
7,000 KB
testcase_22 AC 50 ms
8,744 KB
testcase_23 AC 57 ms
8,780 KB
testcase_24 AC 52 ms
8,780 KB
testcase_25 AC 54 ms
8,780 KB
権限があれば一括ダウンロードができます

ソースコード

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