結果

問題 No.3340 Simple Graph Game
コンテスト
ユーザー titia
提出日時 2025-12-05 03:24:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,430 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 295 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 132,408 KB
最終ジャッジ日時 2025-12-05 03:24:41
合計ジャッジ時間 14,459 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

N,M=map(int,input().split())

E=[[] for i in range(N)]
E_INV=[[] for i in range(N)]

for i in range(M):
    x,y=map(int,input().split())
    x-=1
    y-=1

    E[y].append(x)
    E_INV[x].append(y)

ANS=[-1]*N
for i in range(N):
    if E_INV[i]==[]:
        ANS[i]=0
        
# DFSして帰り際にTOPに点を放り込んでいる。
# NOWで現在地点、USEINDで、どこの辺まで既に見たか、を調べている。
def Top_sort(E):
    Parent=[-1]*N
    USEIND=[0]*N
    TOP=[]

    for ROOT in range(N):
        if Parent[ROOT]!=-1:
            continue
        Parent[ROOT]=ROOT

        NOW=ROOT

        while NOW!=ROOT or USEIND[ROOT]!=len(E[ROOT]):

            if USEIND[NOW]==len(E[NOW]):
                TOP.append(NOW)
                NOW=Parent[NOW]
            elif E[NOW][USEIND[NOW]]==Parent[NOW]:
                USEIND[NOW]+=1
            else:
                NEXT=E[NOW][USEIND[NOW]]
                USEIND[NOW]+=1
                if Parent[NEXT]==-1:
                    Parent[NEXT]=NOW
                    NOW=NEXT
        TOP.append(ROOT)
        
    return TOP[::-1]

TOP=Top_sort(E)

for x in TOP:
    if ANS[x]==0:
        for to in E[x]:
            ANS[to]=1
    elif ANS[x]==1:
        for to in E[x]:
            if ANS[to]==-1:
                ANS[to]=0


if ANS[0]==0:
    print("Bob")
elif ANS[0]==1:
    print("Alice")
else:
    print("Draw")
0