結果

問題 No.1660 Matrix Exponentiation
ユーザー puznekopuzneko
提出日時 2021-11-26 00:30:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,419 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 114,456 KB
最終ジャッジ日時 2023-09-11 02:39:19
合計ジャッジ時間 8,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,536 KB
testcase_01 AC 72 ms
71,284 KB
testcase_02 AC 75 ms
71,396 KB
testcase_03 AC 72 ms
71,012 KB
testcase_04 AC 71 ms
71,532 KB
testcase_05 AC 71 ms
71,224 KB
testcase_06 AC 73 ms
71,456 KB
testcase_07 AC 71 ms
71,204 KB
testcase_08 AC 71 ms
71,532 KB
testcase_09 AC 108 ms
84,212 KB
testcase_10 AC 108 ms
84,232 KB
testcase_11 AC 79 ms
77,516 KB
testcase_12 AC 72 ms
71,264 KB
testcase_13 AC 71 ms
71,264 KB
testcase_14 AC 72 ms
71,212 KB
testcase_15 AC 95 ms
76,412 KB
testcase_16 AC 74 ms
71,396 KB
testcase_17 AC 82 ms
76,260 KB
testcase_18 AC 106 ms
77,316 KB
testcase_19 AC 277 ms
109,220 KB
testcase_20 AC 216 ms
99,852 KB
testcase_21 AC 1,432 ms
114,456 KB
testcase_22 AC 114 ms
82,260 KB
testcase_23 AC 173 ms
91,168 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
n, m, *indata = map(int, stdin.read().split())
offset = 0
g = [[] for i in range(n+1)]
for i in range(m):
    s, t = indata[offset + 2*i],indata[offset + 2*i+1]
    g[s].append(t)

check = [False for i in range(n+1)]
visited = [False for i in range(n+1)]
for i in range(1,n+1):
    if not check[i]:
        que = [(i,0)]
        while que:
            now, inout = que.pop()
            if inout == 0:
                if not check[now]:
                    check[now] == True
                    que.append((now,1))
                    visited[now] = True
                    for j in g[now]:
                        if visited[j]:
                            print(-1)
                            exit()
                        que.append((j,0))
            else:
                visited[now] = False

dp = [0 for i in range(n+1)]
check = [False for i in range(n+1)]
for i in range(1,n+1):
    if not check[i]:
        que = [(i,0)]
        while que:
            now, inout = que.pop()
            if inout == 0:
                if not check[now]:
                    check[now] == True
                    que.append((now,1))
                    for j in g[now]:
                        if not check[j]:
                            que.append((j,0))
            else:
                for j in g[now]:
                    dp[now] = max(dp[now],dp[j]+1)

ans = max(dp) + 1
print("{}".format(ans))
0