結果
| 問題 | No.3340 Simple Graph Game |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-12-05 03:34:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,096 bytes |
| 記録 | |
| コンパイル時間 | 259 ms |
| コンパイル使用メモリ | 82,368 KB |
| 実行使用メモリ | 154,920 KB |
| 最終ジャッジ日時 | 2025-12-05 03:35:00 |
| 合計ジャッジ時間 | 16,833 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 54 WA * 5 |
ソースコード
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)]
ANS=[-1]*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)
if x==y:
ANS[x]=-2
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)
USE=[0]*N
SCC=[]
# SCCを調べるための逆順DFS。
# やっていることはhttps://manabitimes.jp/math/1250 などと同じ。
def dfs2(x):
Q=[x]
USE[x]=1
ANS=[]
while Q:
x=Q.pop()
ANS.append(x)
for to in E_INV[x]:
if USE[to]==0:
USE[to]=1
Q.append(to)
return ANS
TOP_SORT=Top_sort(E)
for x in TOP_SORT:
if USE[x]==0:
SCC.append(dfs2(x))
for scc in SCC:
if len(scc)>1:
for x in scc:
ANS[x]=-2
for x in TOP:
if ANS[x]==0:
continue
L=[]
for to in E_INV[x]:
L.append(ANS[to])
if 0 in L:
ANS[x]=1
continue
if -2 in L:
ANS[x]=-2
continue
if 1 in L:
ANS[x]=0
continue
ANS[x]=-1
if ANS[0]==0:
print("Bob")
elif ANS[0]==1:
print("Alice")
else:
print("Draw")
titia