結果

問題 No.1660 Matrix Exponentiation
ユーザー rin204
提出日時 2021-08-27 21:47:26
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 593 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 81,968 KB
実行使用メモリ 1,021,740 KB
最終ジャッジ日時 2024-11-21 01:33:37
合計ジャッジ時間 14,093 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 23 TLE * 3 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)

n, k = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(k):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    edges[r].append(c)
    
dist = [-1] * n
used = [False] * n

def dfs(pos):
    dist[pos] = max(dist[pos], 0)
    for npos in edges[pos]:
        if used[npos]:
            print(-1)
            exit()
        dfs(npos)
        dist[pos] = max(dist[pos], dist[npos] + 1)

for i in range(n):
    if dist[i] != -1:
        continue
    used[i] = True
    dfs(i)
    used[i] = False
    
print(max(dist) + 1)
0