結果

問題 No.1660 Matrix Exponentiation
ユーザー vwxyz
提出日時 2024-08-15 10:32:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 514 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,672 KB
最終ジャッジ日時 2024-08-15 10:32:59
合計ジャッジ時間 6,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
graph=[[] for x in range(N)]
degree=[0]*N
for k in range(K):
    r,c=map(int,input().split())
    r-=1;c-=1
    graph[r].append(c)
    degree[c]+=1
queue=[]
inf=1<<30
dp=[-inf]*N
for x in range(N):
    if degree[x]==0:
        queue.append(x)
        dp[x]=0
while queue:
    x=queue.pop()
    for y in graph[x]:
        degree[y]-=1
        if degree[y]==0:
            queue.append(y)
            dp[y]=max(dp[y],dp[x]+1)
if sum(degree):
    ans=-1
else:
    ans=max(dp)+1
print(ans)
0