結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー bonKotsubonKotsu
提出日時 2021-06-25 00:21:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,239 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 170,472 KB
実行使用メモリ 9,420 KB
最終ジャッジ日時 2023-09-07 13:31:19
合計ジャッジ時間 3,133 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,700 KB
testcase_01 AC 4 ms
5,716 KB
testcase_02 AC 3 ms
5,768 KB
testcase_03 AC 3 ms
5,728 KB
testcase_04 AC 3 ms
5,808 KB
testcase_05 AC 3 ms
5,796 KB
testcase_06 AC 3 ms
5,916 KB
testcase_07 AC 3 ms
5,928 KB
testcase_08 AC 3 ms
5,740 KB
testcase_09 AC 3 ms
5,832 KB
testcase_10 AC 3 ms
6,040 KB
testcase_11 AC 3 ms
5,888 KB
testcase_12 AC 4 ms
5,808 KB
testcase_13 AC 9 ms
6,108 KB
testcase_14 AC 10 ms
6,072 KB
testcase_15 AC 9 ms
6,120 KB
testcase_16 AC 10 ms
6,220 KB
testcase_17 AC 9 ms
6,108 KB
testcase_18 AC 23 ms
7,208 KB
testcase_19 AC 22 ms
6,888 KB
testcase_20 AC 32 ms
7,364 KB
testcase_21 AC 53 ms
8,312 KB
testcase_22 AC 70 ms
9,060 KB
testcase_23 AC 92 ms
9,360 KB
testcase_24 AC 72 ms
9,420 KB
testcase_25 AC 83 ms
9,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

int n;
const int INF = 1001001001;
vector<int> G[100005];
int dist[100005];
bool seen[100005];
bool loopflag = false;

struct UnionFind {
  vector<int> par, siz;

  // 初期化
  UnionFind(int n) : par(n, -1), siz(n, -1) { }

  int root(int x) {
    if (par[x] == -1) return x;
    else return par[x] = root(par[x]);

  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x), y = root(y);

    if (x == y) return false;

    if (siz[x] < siz[y]) swap(x, y);

    par[y] = x;
    siz[x] += siz[y];
    return true;
  }

  int size(int x) {
    return -siz[root(x)];
  }
};

int main() {
  cin >> n;
  UnionFind uf(n);
  rep(i,n-1) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
    uf.merge(u,v);
  }
  int cnt = 0;
  rep(i,n) {
    if (uf.root(i) == i) cnt++;
  }
  string ans = "Alice";
  if (cnt == 1) ans = "Bob";
  else if (cnt == 2) {
    bool flag = true;
    rep(i,n) {
      if (G[i].size() != 0 && G[i].size() != 2) flag = false;
    }
    if (flag) ans = "Bob";
  }
  cout << ans << endl;



}
0