結果
| 問題 |
No.1660 Matrix Exponentiation
|
| コンテスト | |
| ユーザー |
puzneko
|
| 提出日時 | 2021-11-26 00:20:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,337 bytes |
| コンパイル時間 | 241 ms |
| コンパイル使用メモリ | 82,028 KB |
| 実行使用メモリ | 200,424 KB |
| 最終ジャッジ日時 | 2024-06-28 16:59:44 |
| 合計ジャッジ時間 | 7,707 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 TLE * 1 -- * 5 |
ソースコード
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]:
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))
puzneko