結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ysystem7ysystem7
提出日時 2020-10-17 13:17:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,959 bytes
コンパイル時間 2,865 ms
コンパイル使用メモリ 224,084 KB
実行使用メモリ 7,212 KB
最終ジャッジ日時 2023-09-28 07:41:11
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 23 ms
4,880 KB
testcase_22 AC 27 ms
5,412 KB
testcase_23 AC 26 ms
5,344 KB
testcase_24 AC 29 ms
7,212 KB
testcase_25 AC 25 ms
5,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:106:28: 警告: ‘pos’ may be used uninitialized [-Wmaybe-uninitialized]
  106 |                 bb.pb(a[pos]);
      |                            ^
main.cpp:87:17: 備考: ‘pos’ はここで定義されています
   87 |             int pos;
      |                 ^~~

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

class UnionFind{
public:
    vector<ll> par,num;

    int find(ll v){
        return (par[v]==v)? v: (par[v]=find(par[v]));
    }
    explicit UnionFind(ll N):par(N),num(N,1){
        iota(par.begin(),par.end(),0);
    }
    void unite(ll u,ll v){
        u=find(u),v=find(v);
        if(u==v)return ;
        if(num[u]<num[v])swap(u,v);
        num[u] += num[v];
        par[v] = u;
    }
    bool same(ll u,ll v){
        return find(u) == find(v);
    }
    bool ispar(ll v){
        return v=find(v);
    }
    ll size(ll v){
        return num[find(v)];
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    UnionFind uf(n);
    V<int> a(n-1),b(n-1);
    rep(i,n-1){
        //int a,b;
        cin>>a[i]>>b[i];
        //a--;b--;
        uf.unite(a[i],b[i]);
    }
    set<int> st;
    rep(i,n) st.insert(uf.find(i));
    
    bool f=1;
    if(st.size()==2){
        bool sz_1=0;
        rep(i,n){
            if(uf.size(i)==1) sz_1=1;

        }
        if(sz_1){
            UnionFind uf2(n);
            V<int> deg(n,0);
            int pos;
            rep(i,n-1){
                if(!uf2.same(a[i],b[i])){
                    uf2.unite(a[i],b[i]);
                    deg[a[i]]++;
                    deg[b[i]]++;
                }else pos=i;
            }
            bool dd=1;
            rep(i,n){
                if(deg[i]>2) dd=0;
            }
            if(dd){
                V<int> aa;
                rep(i,n){
                    if(deg[i]==1) aa.push_back(i);
                }
                sort(all(aa));
                V<int> bb;
                bb.pb(a[pos]);
                bb.pb(b[pos]);
                sort(all(bb));
                if(aa!=bb) f=0;
            }
        }
    }else if(st.size()==1) f=0;
    if(!f) out("Bob");
    else out("Alice");
}
0