結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー risujirohrisujiroh
提出日時 2020-01-31 21:35:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 169,452 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 08:52:53
合計ジャッジ時間 2,535 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 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 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 20 ms
4,348 KB
testcase_23 WA -
testcase_24 AC 20 ms
4,348 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct UnionFind {
  vector<int> t;
  int c;
  UnionFind(int n) : t(n, -1), c(0) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
    ++c;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  UnionFind uf(n);
  for (int _ = n - 1; _--; ) {
    int u, v;
    cin >> u >> v;
    uf.unite(u, v);
  }
  if (uf.c == 1 or (uf.c == 2 and (uf.size(0) == 1 or uf.size(0) == n - 1))) {
    cout << "Bob\n";
  } else {
    cout << "Alice\n";
  }
}
0