結果

問題 No.3340 Simple Graph Game
コンテスト
ユーザー The Forsaking
提出日時 2025-11-21 15:30:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 198,656 KB
実行使用メモリ 22,824 KB
最終ジャッジ日時 2025-11-21 15:30:30
合計ジャッジ時間 7,619 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000010, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
int n, m, w[N];

int e[N], ne[N], h[N], idx, din[N];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int f[N];

int main() {
    memset(h, -1, sizeof h);
    cin >> n >> m;
    for (int i = 1, a, b; i < m + 1; i++) {
        scanf("%d%d", &a, &b);
        add(b, a);
        din[a]++;
    }
    queue<int> q;
    for (int i = 1; i < n + 1; i++)
        if (!din[i])
            f[i] = 2, q.push(i);
    while (q.size()) {
        auto u = q.front(); q.pop();
        for (int i = h[u]; ~i; i = ne[i]) {
            int j = e[i];
            --din[j];
            if (!f[j]) {
                if (f[u] == 2) f[j] = 1;
                else if (f[u] == 1 && !din[j]) f[j] = 2;
                else continue;
                q.push(j);
            }
        }
    }
    puts(f[1] == 1 ? "Alice" : f[1] ? "Bob" : "Draw");
    return 0;
}
0