結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー utouto97utouto97
提出日時 2020-02-06 21:58:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,533 bytes
コンパイル時間 2,841 ms
コンパイル使用メモリ 168,968 KB
実行使用メモリ 5,408 KB
最終ジャッジ日時 2023-10-25 22:41:18
合計ジャッジ時間 2,552 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_04 AC 1 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 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 20 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 32 ms
4,348 KB
testcase_21 AC 52 ms
4,880 KB
testcase_22 AC 65 ms
5,408 KB
testcase_23 AC 65 ms
5,408 KB
testcase_24 AC 63 ms
5,408 KB
testcase_25 AC 65 ms
5,408 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]++;
  }

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

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

  return 0;
}
0