結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー kekenx
提出日時 2020-02-14 18:46:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 171,120 KB
実行使用メモリ 9,032 KB
最終ジャッジ日時 2024-10-06 09:46:25
合計ジャッジ時間 2,958 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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