結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー hiro71687khiro71687k
提出日時 2023-02-28 03:17:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,672 bytes
コンパイル時間 5,164 ms
コンパイル使用メモリ 266,468 KB
実行使用メモリ 15,692 KB
最終ジャッジ日時 2023-10-13 10:44:23
合計ジャッジ時間 7,313 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,356 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 10 ms
4,456 KB
testcase_14 AC 8 ms
4,352 KB
testcase_15 AC 9 ms
4,392 KB
testcase_16 AC 9 ms
4,372 KB
testcase_17 AC 10 ms
5,284 KB
testcase_18 AC 28 ms
6,732 KB
testcase_19 AC 32 ms
9,388 KB
testcase_20 AC 43 ms
7,520 KB
testcase_21 AC 74 ms
10,144 KB
testcase_22 AC 96 ms
12,088 KB
testcase_23 AC 103 ms
12,828 KB
testcase_24 AC 110 ms
15,692 KB
testcase_25 AC 101 ms
12,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll inf=10010010010010010;
ll mod=998244353;
template< typename G >
struct LowLink {
  const G &g;
  vector< int > used, ord, low;
  vector< int > articulation;
  vector< pair< int, int > > bridge;
 
  LowLink(const G &g) : g(g) {}
 
  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for(auto &to : g[idx]) {
      if(!used[to]) {
        ++cnt;
        k = dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if(ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int) to));
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return k;
  }
 
  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for(int i = 0; i < g.size(); i++) {
      if(!used[i]) k = dfs(i, k, -1);
    }
  }
};

struct unionfind
{
    vector<ll>par,siz;
    unionfind(ll n): par(n,-1),siz(n,1){}
    ll root(ll x){
        if (par[x]==-1)
        {
            return x;
        }else{
            return par[x]=root(par[x]);
        }
    }
    bool issame(ll x,ll y){
        return root(x)==root(y);
    }
    bool unite(ll x,ll y){
        x=root(x);
        y=root(y);
        if (x==y)
        {
            return false;
        }
        if (siz[x]<siz[y])
        {
            swap(x,y);
        }
        par[y]=x;
        siz[x]+=siz[y];
        return true;
    }
    ll size(ll x){
        return siz[root(x)];
    }
};
int main(){
    ll n;
    cin >> n;
    unionfind uf(n);
    vector<ll>u(n-1),v(n-1);
    vector<vector<ll>>g(n);
    for (ll i = 0; i < n-1; i++)
    {
        cin >> u[i] >> v[i];
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
        uf.unite(u[i],v[i]);
    }
    ll ans=0;
    vector<ll>memo(n,0);
    for (ll i = 0; i < n; i++)
    {
        if (memo[uf.root(i)]==0)
        {
            ans+=1;
        }
        memo[uf.root(i)]+=1;
    }
    if (ans==1)
    {
        cout << "Bob" << endl;
        return 0;
    }else if (ans!=2)
    {
        cout << "Alice" << endl;
        return 0;
    }
    LowLink<vector<vector<ll>>>lowlink(g);
    lowlink.build();
    if (lowlink.bridge.empty())
    {
        cout << "Bob" <<endl;
    }else{
        cout << "Alice" << endl;
    }
    
}
0