結果

問題 No.1565 Union
ユーザー kotatsugamekotatsugame
提出日時 2021-06-29 20:11:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 76,536 KB
実行使用メモリ 16,732 KB
最終ジャッジ日時 2023-09-08 05:21:41
合計ジャッジ時間 6,309 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,832 KB
testcase_01 AC 4 ms
9,572 KB
testcase_02 AC 4 ms
9,648 KB
testcase_03 AC 4 ms
9,520 KB
testcase_04 AC 4 ms
9,500 KB
testcase_05 AC 4 ms
9,648 KB
testcase_06 AC 5 ms
9,728 KB
testcase_07 AC 4 ms
9,520 KB
testcase_08 AC 4 ms
9,708 KB
testcase_09 AC 4 ms
9,832 KB
testcase_10 AC 63 ms
11,168 KB
testcase_11 AC 103 ms
14,060 KB
testcase_12 AC 116 ms
12,688 KB
testcase_13 AC 39 ms
10,856 KB
testcase_14 AC 132 ms
13,836 KB
testcase_15 AC 179 ms
16,116 KB
testcase_16 AC 184 ms
15,872 KB
testcase_17 AC 183 ms
15,996 KB
testcase_18 AC 190 ms
16,060 KB
testcase_19 AC 185 ms
15,976 KB
testcase_20 AC 136 ms
16,732 KB
testcase_21 AC 135 ms
16,544 KB
testcase_22 AC 136 ms
16,532 KB
testcase_23 AC 137 ms
16,560 KB
testcase_24 AC 135 ms
16,548 KB
testcase_25 AC 138 ms
16,548 KB
testcase_26 AC 136 ms
16,584 KB
testcase_27 AC 137 ms
16,552 KB
testcase_28 AC 139 ms
16,536 KB
testcase_29 AC 137 ms
16,588 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<int>G[2<<17];
int dist[2<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=1;i<N;i++)dist[i]=M+1;
	queue<int>P;
	P.push(0);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(int v:G[u])if(dist[v]>dist[u]+1)
		{
			dist[v]=dist[u]+1;
			P.push(v);
		}
	}
	if(dist[N-1]==M+1)cout<<-1<<endl;
	else cout<<dist[N-1]<<endl;
}
0