結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー monnumonnu
提出日時 2020-09-29 20:58:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 169,428 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 16:36:43
合計ジャッジ時間 4,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 7 ms
4,384 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 18 ms
4,376 KB
testcase_19 AC 18 ms
4,380 KB
testcase_20 AC 27 ms
4,376 KB
testcase_21 AC 42 ms
4,380 KB
testcase_22 AC 54 ms
4,376 KB
testcase_23 AC 59 ms
4,380 KB
testcase_24 AC 57 ms
4,376 KB
testcase_25 AC 59 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000000000
using ll=long long;
using Graph=vector<vector<int>>;

vector<int> parent;
int find(int x){
  int y=parent[x];
  while(y!=parent[y]){
    y=find(y);
  }
  return parent[x]=y;
}
void unite(int a,int b){
  int x=find(a);
  int y=find(b);
  if(x!=y){
    parent[x]=y;
  }
}

int main(){
  int N;
  cin>>N;
  vector<int> cnt(N,0);
  parent.resize(N);
  for(int i=0;i<N;i++){
    parent[i]=i;
  }
  for(int i=0;i<N-1;i++){
    int u,v;
    cin>>u>>v;
    cnt[u]++;
    cnt[v]++;
    unite(u,v);
  }

  vector<int> num(N,0);
  for(int i=0;i<N;i++){
    num[find(i)]=1;
  }
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=num[i];
  }

  if(sum==1){
    cout<<"Bob"<<endl;
  }else if(sum>2){
    cout<<"Alice"<<endl;
  }else{
    int flag=2;
    for(int i=0;i<N;i++){
      if(cnt[i]==2){
        continue;
      }else if(cnt[i]==0){
        flag--;
      }else{
        flag=0;
      }
    }
    if(flag==1){
      cout<<"Bob"<<endl;
    }else{
      cout<<"Alice"<<endl;
    }
  }
}
0