結果

問題 No.1660 Matrix Exponentiation
ユーザー kotatsugamekotatsugame
提出日時 2021-08-27 22:04:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 76,168 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2023-08-13 09:02:54
合計ジャッジ時間 2,880 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,416 KB
testcase_01 AC 3 ms
6,536 KB
testcase_02 AC 3 ms
6,420 KB
testcase_03 AC 3 ms
6,468 KB
testcase_04 AC 3 ms
6,640 KB
testcase_05 AC 3 ms
6,404 KB
testcase_06 AC 3 ms
6,416 KB
testcase_07 AC 4 ms
6,400 KB
testcase_08 AC 3 ms
6,460 KB
testcase_09 AC 4 ms
6,740 KB
testcase_10 AC 4 ms
6,644 KB
testcase_11 AC 4 ms
6,744 KB
testcase_12 AC 3 ms
6,456 KB
testcase_13 AC 3 ms
6,416 KB
testcase_14 AC 3 ms
6,656 KB
testcase_15 AC 3 ms
6,428 KB
testcase_16 AC 3 ms
6,416 KB
testcase_17 AC 3 ms
6,512 KB
testcase_18 AC 3 ms
6,440 KB
testcase_19 AC 59 ms
8,496 KB
testcase_20 AC 40 ms
8,180 KB
testcase_21 AC 60 ms
7,620 KB
testcase_22 AC 5 ms
7,296 KB
testcase_23 AC 25 ms
7,672 KB
testcase_24 AC 86 ms
10,288 KB
testcase_25 AC 47 ms
7,732 KB
testcase_26 AC 90 ms
10,368 KB
testcase_27 AC 62 ms
9,968 KB
testcase_28 AC 75 ms
9,320 KB
testcase_29 AC 71 ms
10,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#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;
}
0