結果

問題 No.1660 Matrix Exponentiation
ユーザー kotatsugamekotatsugame
提出日時 2021-08-27 22:04:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 76,252 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-05-01 02:39:08
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,528 KB
testcase_01 AC 3 ms
6,528 KB
testcase_02 AC 4 ms
6,528 KB
testcase_03 AC 4 ms
6,656 KB
testcase_04 AC 3 ms
6,656 KB
testcase_05 AC 4 ms
6,528 KB
testcase_06 AC 4 ms
6,528 KB
testcase_07 AC 5 ms
6,528 KB
testcase_08 AC 4 ms
6,528 KB
testcase_09 AC 5 ms
6,876 KB
testcase_10 AC 6 ms
6,784 KB
testcase_11 AC 6 ms
6,752 KB
testcase_12 AC 4 ms
6,656 KB
testcase_13 AC 4 ms
6,528 KB
testcase_14 AC 4 ms
6,656 KB
testcase_15 AC 4 ms
6,528 KB
testcase_16 AC 4 ms
6,528 KB
testcase_17 AC 4 ms
6,528 KB
testcase_18 AC 5 ms
6,528 KB
testcase_19 AC 69 ms
8,576 KB
testcase_20 AC 44 ms
8,320 KB
testcase_21 AC 65 ms
7,816 KB
testcase_22 AC 7 ms
7,296 KB
testcase_23 AC 27 ms
7,808 KB
testcase_24 AC 104 ms
10,496 KB
testcase_25 AC 53 ms
7,892 KB
testcase_26 AC 104 ms
10,496 KB
testcase_27 AC 67 ms
10,112 KB
testcase_28 AC 85 ms
9,472 KB
testcase_29 AC 82 ms
10,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-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