結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー utouto97utouto97
提出日時 2020-02-06 22:01:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,526 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 164,460 KB
実行使用メモリ 5,448 KB
最終ジャッジ日時 2023-10-25 22:41:34
合計ジャッジ時間 2,946 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 31 ms
4,348 KB
testcase_21 AC 48 ms
4,920 KB
testcase_22 AC 61 ms
5,448 KB
testcase_23 AC 64 ms
5,448 KB
testcase_24 AC 64 ms
5,448 KB
testcase_25 AC 65 ms
5,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

class UnionFind {
public:
  int n;
  vector<int> par, rnk;

  UnionFind(int n_) {
    n = n_;
    par.resize(n);
    rnk.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rnk[i] = 0;
    }
  }

  int find(int x) {
    if (par[x] == x)
      return x;
    return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y])
        rnk[x]++;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }
};

signed main() {
  int n;
  cin >> n;
  UnionFind uf(n);
  vi d(n);
  rep(i, 0, n - 1) {
    int u, v;
    cin >> u >> v;
    uf.unite(u, v);
    d[u]++;
    d[v]++;
  }

  int cnt = 0;
  bool d1 = false;
  rep(i, 0, n) {
    if(uf.find(i) == i) cnt++;
    if (d[i] == 1)
      d1 = true;
  }

  if (cnt > 2)
    cout << "Alice" << endl;
  else if (cnt == 2 and d1)
    cout << "Alice" << endl;
  else
    cout << "Bob" << endl;

  return 0;
}
0