結果
| 問題 |
No.1660 Matrix Exponentiation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-27 22:04:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 76 ms / 2,000 ms |
| コード長 | 570 bytes |
| コンパイル時間 | 644 ms |
| コンパイル使用メモリ | 76,140 KB |
| 実行使用メモリ | 10,564 KB |
| 最終ジャッジ日時 | 2024-11-21 02:28:41 |
| 合計ジャッジ時間 | 2,299 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<int>G[1<<17];
int indeg[1<<17];
int dist[1<<17];
main()
{
cin>>N>>M;
for(int i=0;i<M;i++)
{
int a,b;cin>>a>>b;
G[a-1].push_back(b-1);
indeg[b-1]++;
}
queue<int>P;
for(int i=0;i<N;i++)if(!indeg[i])
{
P.push(i);
}
int sz=0,mx=0;
while(!P.empty())
{
int u=P.front();P.pop();
sz++;
if(mx<dist[u])mx=dist[u];
for(int v:G[u])
{
if(dist[v]<dist[u]+1)dist[v]=dist[u]+1;
if(!--indeg[v])P.push(v);
}
}
if(sz<N)cout<<-1<<endl;
else cout<<mx+1<<endl;
}