結果

問題 No.1660 Matrix Exponentiation
ユーザー convexineqconvexineq
提出日時 2021-08-28 21:21:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 477 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 87,328 KB
実行使用メモリ 92,216 KB
最終ジャッジ日時 2023-08-14 03:27:15
合計ジャッジ時間 5,673 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,456 KB
testcase_01 AC 68 ms
71,360 KB
testcase_02 AC 68 ms
71,320 KB
testcase_03 AC 68 ms
71,412 KB
testcase_04 AC 70 ms
71,328 KB
testcase_05 WA -
testcase_06 AC 70 ms
71,368 KB
testcase_07 WA -
testcase_08 AC 69 ms
71,244 KB
testcase_09 AC 92 ms
85,204 KB
testcase_10 AC 85 ms
85,496 KB
testcase_11 AC 72 ms
77,088 KB
testcase_12 AC 69 ms
71,432 KB
testcase_13 AC 69 ms
71,364 KB
testcase_14 AC 70 ms
71,568 KB
testcase_15 AC 78 ms
75,276 KB
testcase_16 AC 70 ms
71,352 KB
testcase_17 AC 70 ms
71,336 KB
testcase_18 AC 82 ms
75,088 KB
testcase_19 AC 211 ms
86,096 KB
testcase_20 AC 173 ms
85,984 KB
testcase_21 AC 190 ms
81,284 KB
testcase_22 AC 114 ms
84,304 KB
testcase_23 AC 151 ms
84,088 KB
testcase_24 AC 227 ms
90,196 KB
testcase_25 AC 186 ms
92,216 KB
testcase_26 AC 221 ms
90,356 KB
testcase_27 AC 73 ms
76,760 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
g = [[] for _ in range(n)]
deg = [0]*n
for _ in range(k):
    a,b = map(int,input().split())
    if a == b:
        print(-1)
        exit()
    g[a-1].append(b-1)
    deg[b-1] += 1

dp = [0]*n
q = [i for i in range(n) if deg[i]==0]
for i in q: dp[i] = 1
while q:
    v = q.pop()
    for c in g[v]:
        dp[c] = max(dp[c],dp[v]+1)
        deg[c] -= 1
        if deg[c] == 0:
            q.append(c)
    
print(-1 if min(dp) == -1 else max(dp))
0