結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー takumi152takumi152
提出日時 2020-01-31 21:40:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,615 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 108,692 KB
実行使用メモリ 9,080 KB
最終ジャッジ日時 2023-10-17 09:00:37
合計ジャッジ時間 2,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 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,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 15 ms
5,120 KB
testcase_19 AC 14 ms
5,120 KB
testcase_20 AC 24 ms
6,176 KB
testcase_21 AC 38 ms
7,760 KB
testcase_22 AC 49 ms
8,816 KB
testcase_23 AC 54 ms
9,080 KB
testcase_24 AC 50 ms
9,080 KB
testcase_25 AC 57 ms
9,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <queue>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

struct unionfind {
  vector<int> group;

  unionfind(int n) {
    group = vector<int>(n);
    for (int i = 0; i < n; i++) group[i] = i;
  }

  int root(int x) {
    if (group[x] == x) return x;
    return group[x] = root(group[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    group[rx] = ry;
  }

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<vector<int> > edge(n);
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  unionfind uf(n);
  for (int i = 0; i < n; i++) {
    for (auto &x: edge[i]) {
      uf.unite(i, x);
    }
  }

  unordered_map<int, int> count;
  for (int i = 0; i < n; i++) {
    count[uf.root(i)]++;
  }

  int maximum = 0;
  for (auto &x: count) {
    if (x.second > maximum) {
      maximum = x.second;
    }
  }

  bool good = false;
  if (maximum == n) good = true;
  else if (maximum == n-1) {
    int deg2count = 0;
    for (int i = 0; i < n; i++) {
      if (edge[i].size() == 2) deg2count++;
    }
    if (deg2count == n-1) good = true;
  }

  if (good) cout << "Bob" << endl;
  else cout << "Alice" << endl;

  return 0;
}
0