結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー MayimgMayimg
提出日時 2020-02-01 07:24:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 207,968 KB
実行使用メモリ 10,104 KB
最終ジャッジ日時 2023-10-18 23:44:50
合計ジャッジ時間 3,795 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 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,392 KB
testcase_15 AC 6 ms
4,368 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 6 ms
5,188 KB
testcase_18 AC 15 ms
5,376 KB
testcase_19 AC 18 ms
8,732 KB
testcase_20 AC 29 ms
7,728 KB
testcase_21 AC 46 ms
8,256 KB
testcase_22 AC 72 ms
9,840 KB
testcase_23 AC 73 ms
10,104 KB
testcase_24 AC 66 ms
10,104 KB
testcase_25 AC 65 ms
10,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : siz(x), a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
    return true;
  }

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

  int size(int x) {
    return -a[root(x)];
  }
  
  int connected_component() {
  	return siz;
  }
};
const int INF = 1 << 30;
bool dfs (int cur, int from, int c, const vector<vector<int>>& g, vector<int>& order, vector<int>& low) {
  order[cur] = c++;
  low[cur] = order[cur];
  bool res = false;
  for (int nbr : g[cur]) {
    if (order[nbr] == INF) {
      res |= dfs (nbr, cur, c, g, order, low);
      low[cur] = min(low[cur], low[nbr]);
      if (low[nbr] == order[nbr]) {
        res = true;
      }
    } else if (nbr != from) {
      low[cur] = min(low[cur], low[nbr]);
    }
  }
  return res;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  UnionFind uf(n);
  for (int i = 0; i + 1 < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    uf.unite(u, v);
  }
  vector<int> order(n, INF), low(n, INF);
  bool b = false;
  for (int i = 0; i < n; i++) {
    if (uf.size(i) > 1 && uf.root(i) == i) {
      order[i] = 0;
      b |= dfs (i, -1, 0, g, order, low);
    }
  }
  if (uf.connected_component() > 2 || (uf.connected_component() > 1 && b)) cout << "Alice\n";
  else cout << "Bob\n";
  return 0;
}
0