結果

問題 No.3340 Simple Graph Game
コンテスト
ユーザー Koi
提出日時 2025-11-13 21:38:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 4,349 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 126,452 KB
最終ジャッジ日時 2025-11-18 10:37:13
合計ジャッジ時間 10,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
Graph = [[] for _ in range(N)]
RevG = [[] for _ in range(N)]
Outs = [0] * N
for i in range(M):
    u, v = map(int, input().split())
    Graph[u - 1].append(v - 1)
    RevG[v - 1].append(u - 1)
    Outs[u - 1] += 1
L = []
Result = [-1] * N
#Result[i]:=頂点iに駒がある状態でゲームをした時、0なら先手が勝つ1なら後手が勝つ-1なら引き分け
for i in range(N):
    if(Outs[i] == 0):
        L.append(i)
        Result[i] = 1
while len(L):
    p = L.pop()
    if(Result[p] == 1):
        for pre in RevG[p]:
            if(Result[pre] == -1):
                Result[pre] = 0
                L.append(pre)
    elif(Result[p] == 0):
        for pre in RevG[p]:
            Outs[pre] -= 1
            if(Outs[pre] == 0):
                L.append(pre)
                Result[pre] = 1
    else:
        assert(False)
if(Result[0] == 0):
    print("Alice")
elif(Result[0] == 1):
    print("Bob")
else:
    print("Draw")
0