結果

問題 No.1244 Black Segment
ユーザー kotatsugamekotatsugame
提出日時 2020-10-02 21:56:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 77,056 KB
実行使用メモリ 10,164 KB
最終ジャッジ日時 2023-09-23 04:55:32
合計ジャッジ時間 4,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,464 KB
testcase_01 AC 4 ms
6,484 KB
testcase_02 AC 4 ms
6,424 KB
testcase_03 AC 4 ms
6,460 KB
testcase_04 AC 4 ms
6,452 KB
testcase_05 AC 4 ms
6,468 KB
testcase_06 AC 4 ms
6,540 KB
testcase_07 AC 4 ms
6,484 KB
testcase_08 AC 3 ms
6,600 KB
testcase_09 AC 4 ms
6,436 KB
testcase_10 AC 4 ms
6,428 KB
testcase_11 AC 4 ms
6,464 KB
testcase_12 AC 3 ms
6,480 KB
testcase_13 AC 6 ms
6,556 KB
testcase_14 AC 52 ms
7,788 KB
testcase_15 AC 6 ms
6,568 KB
testcase_16 AC 51 ms
7,796 KB
testcase_17 AC 6 ms
6,548 KB
testcase_18 AC 49 ms
8,712 KB
testcase_19 AC 68 ms
9,152 KB
testcase_20 AC 77 ms
9,484 KB
testcase_21 AC 75 ms
9,504 KB
testcase_22 AC 77 ms
9,452 KB
testcase_23 AC 81 ms
9,508 KB
testcase_24 AC 84 ms
9,584 KB
testcase_25 AC 79 ms
9,592 KB
testcase_26 AC 78 ms
9,592 KB
testcase_27 AC 84 ms
9,976 KB
testcase_28 AC 81 ms
9,708 KB
testcase_29 AC 78 ms
9,624 KB
testcase_30 AC 81 ms
9,712 KB
testcase_31 AC 80 ms
9,980 KB
testcase_32 AC 84 ms
9,724 KB
testcase_33 AC 81 ms
9,656 KB
testcase_34 AC 79 ms
9,616 KB
testcase_35 AC 78 ms
10,116 KB
testcase_36 AC 82 ms
10,084 KB
testcase_37 AC 80 ms
10,164 KB
testcase_38 AC 84 ms
9,976 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,A,B;
vector<int>G[1<<17];
int vis[1<<17];
main()
{
	cin>>N>>M>>A>>B;
	for(int i=0;i<=N;i++)vis[i]=1e9;
	A--;
	for(;M--;)
	{
		int l,r;cin>>l>>r;
		l--;
		G[l].push_back(r);
		G[r].push_back(l);
	}
	queue<int>P;
	for(int i=0;i<=A;i++)
	{
		P.push(i);
		vis[i]=0;
	}
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(int v:G[u])if(vis[v]>vis[u]+1)
		{
			vis[v]=vis[u]+1;
			P.push(v);
		}
	}
	int ans=1e9;
	for(int i=B;i<=N;i++)if(ans>vis[i])ans=vis[i];
	cout<<(ans==(int)1e9?-1:ans)<<endl;
}
0