結果

問題 No.1660 Matrix Exponentiation
ユーザー hir355hir355
提出日時 2021-08-27 22:41:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 661 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 101,016 KB
最終ジャッジ日時 2024-11-21 03:46:34
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,132 KB
testcase_01 AC 38 ms
52,620 KB
testcase_02 AC 37 ms
53,232 KB
testcase_03 AC 38 ms
52,280 KB
testcase_04 AC 38 ms
53,044 KB
testcase_05 AC 37 ms
52,364 KB
testcase_06 AC 38 ms
52,540 KB
testcase_07 AC 42 ms
52,364 KB
testcase_08 AC 37 ms
52,212 KB
testcase_09 AC 58 ms
76,756 KB
testcase_10 AC 56 ms
76,712 KB
testcase_11 AC 56 ms
76,932 KB
testcase_12 AC 39 ms
52,252 KB
testcase_13 AC 38 ms
52,396 KB
testcase_14 AC 38 ms
52,204 KB
testcase_15 WA -
testcase_16 AC 39 ms
52,680 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 86 ms
85,556 KB
testcase_23 WA -
testcase_24 AC 260 ms
98,176 KB
testcase_25 AC 222 ms
101,016 KB
testcase_26 AC 263 ms
98,188 KB
testcase_27 AC 159 ms
97,680 KB
testcase_28 AC 276 ms
95,544 KB
testcase_29 AC 211 ms
97,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
g = [[] for _ in range(n)]
g2 = [[] for _ in range(n)]
inv = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g2[b - 1].append(a - 1)
    inv[b - 1] += 1
s = []
d = [-1] * n
for i in range(n):
    if inv[i] == 0:
        s.append(i)
        d[i] = 0
while s:
    p = s.pop()
    for node in g[p]:
        inv[node] -= 1
        if inv[node] == 0:
            t = -1
            for node2 in g2[node]:
                if t < d[node2]:
                    t = d[node2]
            d[node] = d[node2] + 1
            s.append(node)
if -1 in d:
    print(-1)
else:
    print(max(d) + 1)
0