結果

問題 No.3340 Simple Graph Game
コンテスト
ユーザー こめだわら
提出日時 2025-11-13 21:39:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 2,185 bytes
コンパイル時間 2,439 ms
コンパイル使用メモリ 286,912 KB
実行使用メモリ 26,756 KB
最終ジャッジ日時 2025-11-18 10:37:08
合計ジャッジ時間 5,851 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define rep(i,n) for(ll i=0;i<n;++i)
#define all(a) (a).begin(),(a).end()
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); }
template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a){
    if (a.empty()) return os;
    os << a.front();
    for (auto e : a | views::drop(1)){
        os << ' ' << e;
    }
    return os;
}

void dump(auto ...vs){
    ((cout << vs << ' '), ...) << endl;
}



void solve() {
    ll N,M;
    cin>>N>>M;
    vector<vector<ll>> edge(N);
    vector<vector<ll>> edge_inv(N);
    rep(i,M){
        ll u,v;
        cin>>u>>v;
        u--;
        v--;
        edge[u].push_back(v);
        edge_inv[v].push_back(u);
    }
    vector<ll> D(N);
    stack<ll> leaf;
    vector<ll> win(N,0);
    rep(i,N){
        D[i]=edge[i].size();
        if (D[i]==0){
            leaf.push(i);
        }
    }
    while (leaf.size()>0){
        ll cp=leaf.top();leaf.pop();
        win[cp]=-1;
        for (ll np:edge_inv[cp]){
            if (win[np]!=1){
                win[np]=1;
                for (ll nnp:edge_inv[np]){
                    D[nnp]--;
                    if (D[nnp]==0){
                        leaf.push(nnp);
                    }
                }
            }
        }
    }
    if (win[0]==1){
        cout<<"Alice"<<'\n';
    }
    else if (win[0]==-1){
        cout<<"Bob"<<'\n';
    }
    else{
        cout<<"Draw"<<'\n';
    }
    return;
}


int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll T=1;
    while (T--){
        solve();
    }
    return 0;
}
0