結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー StrorkisStrorkis
提出日時 2020-01-31 23:04:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 999 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 72,440 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-10-17 11:59:07
合計ジャッジ時間 2,191 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 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 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 9 ms
5,020 KB
testcase_18 AC 25 ms
5,184 KB
testcase_19 AC 28 ms
8,088 KB
testcase_20 AC 40 ms
7,296 KB
testcase_21 AC 61 ms
8,088 KB
testcase_22 AC 83 ms
9,408 KB
testcase_23 AC 104 ms
9,672 KB
testcase_24 AC 93 ms
9,672 KB
testcase_25 AC 101 ms
9,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef vector<vector<int>> graph;

bool f(graph& g, int ord[], int low[], int p, int u) {
  bool flag = false;
  int k = ord[u]+1;
  for (int v : g[u]) {
    if (ord[v] < 0) {
      ord[v] = k++;
      low[v] = ord[v];
      flag = f(g, ord, low, u, v);
      low[u] = min(low[u], low[v]);
      if (ord[u] < low[v]) flag = true;
    }
    else if (v != p) {
      low[u] = min(low[u], ord[v]);
    }
  }
  return flag;
}

int main() {
  int n;
  cin >> n;
  graph g(n);
  for (int i = 0; i < n-1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  int ord[n] = {}, low[n] = {};
  for (int i = 1; i < n; i++) ord[i] = -1;
  bool bridge = f(g, ord, low, -1, 0);
  
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (ord[i] < 0) count++;
  }

  if (count > 1) cout << "Alice" << endl;
  else if (count == 1) {
    cout << (bridge ? "Alice" : "Bob") << endl;
  }
  else cout << "Bob" << endl;
}
0