結果

問題 No.1660 Matrix Exponentiation
ユーザー 👑 rin204rin204
提出日時 2021-08-27 21:47:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 593 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 848,908 KB
最終ジャッジ日時 2024-05-01 02:13:27
合計ジャッジ時間 7,260 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,280 KB
testcase_01 AC 33 ms
52,196 KB
testcase_02 AC 32 ms
52,744 KB
testcase_03 AC 34 ms
52,648 KB
testcase_04 AC 33 ms
52,720 KB
testcase_05 AC 31 ms
52,720 KB
testcase_06 AC 32 ms
53,776 KB
testcase_07 AC 35 ms
52,260 KB
testcase_08 AC 33 ms
52,768 KB
testcase_09 AC 43 ms
65,384 KB
testcase_10 AC 42 ms
65,036 KB
testcase_11 AC 36 ms
63,192 KB
testcase_12 AC 33 ms
53,532 KB
testcase_13 AC 31 ms
53,548 KB
testcase_14 AC 32 ms
53,192 KB
testcase_15 AC 44 ms
62,288 KB
testcase_16 AC 33 ms
53,856 KB
testcase_17 AC 34 ms
53,172 KB
testcase_18 AC 61 ms
71,564 KB
testcase_19 AC 279 ms
85,628 KB
testcase_20 AC 199 ms
84,228 KB
testcase_21 AC 734 ms
84,112 KB
testcase_22 AC 67 ms
75,576 KB
testcase_23 AC 149 ms
82,316 KB
testcase_24 TLE -
testcase_25 AC 123 ms
85,500 KB
testcase_26 TLE -
testcase_27 AC 120 ms
87,088 KB
testcase_28 MLE -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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