結果
| 問題 | No.1660 Matrix Exponentiation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-30 14:47:18 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 253 ms / 2,000 ms |
| コード長 | 438 bytes |
| 記録 | |
| コンパイル時間 | 150 ms |
| コンパイル使用メモリ | 84,480 KB |
| 実行使用メモリ | 93,184 KB |
| 最終ジャッジ日時 | 2026-05-30 14:47:29 |
| 合計ジャッジ時間 | 10,568 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
from collections import deque
n,k=map(int,input().split())
x=[0]*n
v=[[] for i in range(n)]
for i in range(k):
a,b=map(int,input().split());a-=1;b-=1
v[b].append(a);x[a]+=1
f=deque();dp=[0]*n
for i in range(n):
if not x[i]:
f.append(i)
while f:
q=f.pop()
for i in v[q]:
dp[i]=max(dp[i],dp[q]+1)
x[i]-=1
if not x[i]:
f.append(i)
if max(x):
print(-1);exit()
print(max(dp)+1)