結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー kekenxkekenx
提出日時 2020-02-14 18:46:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 167,072 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-04-16 01:09:27
合計ジャッジ時間 3,837 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,144 KB
testcase_01 AC 3 ms
5,888 KB
testcase_02 AC 4 ms
6,144 KB
testcase_03 AC 4 ms
6,016 KB
testcase_04 AC 4 ms
6,144 KB
testcase_05 AC 4 ms
6,144 KB
testcase_06 AC 4 ms
6,016 KB
testcase_07 AC 4 ms
6,144 KB
testcase_08 AC 4 ms
6,016 KB
testcase_09 AC 4 ms
6,144 KB
testcase_10 AC 4 ms
6,144 KB
testcase_11 AC 4 ms
6,144 KB
testcase_12 AC 4 ms
6,016 KB
testcase_13 AC 8 ms
6,272 KB
testcase_14 AC 7 ms
6,528 KB
testcase_15 AC 7 ms
6,528 KB
testcase_16 AC 7 ms
6,400 KB
testcase_17 AC 8 ms
6,912 KB
testcase_18 AC 16 ms
7,040 KB
testcase_19 AC 17 ms
8,448 KB
testcase_20 AC 25 ms
8,064 KB
testcase_21 AC 40 ms
8,320 KB
testcase_22 AC 69 ms
8,996 KB
testcase_23 AC 56 ms
9,216 KB
testcase_24 AC 61 ms
9,088 KB
testcase_25 AC 60 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
const int MAXN = 100005;

vector<int> G[MAXN];
vector<bool> visited(MAXN, false);

void dfs(int c) {
  visited[c] = true;
  for (int i = 0; i < G[c].size(); ++i) {
    int next = G[c][i];
    if (!visited[next]) dfs(next);
  }
}

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (!visited[i]) {
      dfs(i);
      cnt++;
    }
  }

  if (cnt == 1) {
    puts("Bob");
  } else if (cnt > 2) {
    puts("Alice");
  } else {
    for (int i = 0; i < N; ++i) {
      if (G[i].size() == 1) {
	puts("Alice");
	return 0;
      }
    }
    puts("Bob");
  }
  return 0;
}
0