結果

問題 No.1660 Matrix Exponentiation
ユーザー puznekopuzneko
提出日時 2021-11-26 00:21:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,377 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 195,600 KB
最終ジャッジ日時 2023-09-11 02:31:49
合計ジャッジ時間 9,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,456 KB
testcase_01 AC 78 ms
71,028 KB
testcase_02 AC 76 ms
71,356 KB
testcase_03 AC 77 ms
70,852 KB
testcase_04 AC 77 ms
71,352 KB
testcase_05 AC 77 ms
71,200 KB
testcase_06 AC 76 ms
70,848 KB
testcase_07 AC 77 ms
71,188 KB
testcase_08 AC 76 ms
71,028 KB
testcase_09 AC 117 ms
83,264 KB
testcase_10 AC 116 ms
83,296 KB
testcase_11 AC 81 ms
76,476 KB
testcase_12 AC 75 ms
71,332 KB
testcase_13 AC 76 ms
71,040 KB
testcase_14 AC 77 ms
71,048 KB
testcase_15 AC 95 ms
76,348 KB
testcase_16 AC 78 ms
71,252 KB
testcase_17 AC 81 ms
76,124 KB
testcase_18 WA -
testcase_19 AC 296 ms
108,832 KB
testcase_20 AC 225 ms
99,240 KB
testcase_21 AC 1,208 ms
114,144 KB
testcase_22 AC 120 ms
81,428 KB
testcase_23 AC 183 ms
90,652 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)]
for i in range(1,n+1):
    if not check[i]:
        que = [(i,0)]
        visited = set()
        while que:
            now, inout = que.pop()
            if inout == 0:
                if not check[now]:
                    check[now] == True
                    que.append((now,1))
                    visited.add(now)
                    for j in g[now]:
                        if j in visited:
                            print(-1)
                            exit()
                        que.append((j,0))
            else:
                visited.remove(now)

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)]
        check[i] = True
        while que:
            now, inout = que.pop()
            if inout == 0:
                que.append((now,1))
                for j in g[now]:
                    if not check[j]:
                        check[j] = True
                        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