結果

問題 No.1244 Black Segment
ユーザー publflpublfl
提出日時 2020-10-02 22:55:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 55,212 KB
実行使用メモリ 9,080 KB
最終ジャッジ日時 2023-09-24 22:30:27
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,376 KB
testcase_01 AC 4 ms
5,272 KB
testcase_02 AC 3 ms
5,300 KB
testcase_03 AC 4 ms
5,388 KB
testcase_04 AC 3 ms
5,320 KB
testcase_05 AC 3 ms
5,312 KB
testcase_06 AC 3 ms
5,324 KB
testcase_07 AC 3 ms
5,396 KB
testcase_08 AC 3 ms
5,372 KB
testcase_09 AC 3 ms
5,368 KB
testcase_10 AC 4 ms
5,336 KB
testcase_11 AC 3 ms
5,384 KB
testcase_12 AC 3 ms
5,400 KB
testcase_13 AC 5 ms
5,448 KB
testcase_14 AC 25 ms
6,708 KB
testcase_15 AC 4 ms
5,492 KB
testcase_16 AC 26 ms
6,756 KB
testcase_17 AC 4 ms
5,492 KB
testcase_18 AC 28 ms
7,684 KB
testcase_19 AC 41 ms
7,940 KB
testcase_20 AC 46 ms
8,272 KB
testcase_21 AC 50 ms
8,400 KB
testcase_22 AC 50 ms
8,360 KB
testcase_23 AC 53 ms
8,504 KB
testcase_24 AC 54 ms
8,476 KB
testcase_25 AC 50 ms
8,504 KB
testcase_26 AC 49 ms
8,472 KB
testcase_27 AC 55 ms
8,848 KB
testcase_28 AC 54 ms
8,580 KB
testcase_29 AC 52 ms
8,544 KB
testcase_30 AC 53 ms
8,632 KB
testcase_31 AC 56 ms
8,620 KB
testcase_32 AC 59 ms
8,684 KB
testcase_33 AC 57 ms
8,636 KB
testcase_34 AC 52 ms
8,816 KB
testcase_35 AC 50 ms
8,972 KB
testcase_36 AC 55 ms
9,040 KB
testcase_37 AC 56 ms
8,876 KB
testcase_38 AC 53 ms
9,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <queue>
#define MAX 123456789
int dist[100010];
std::vector<int> V[100010];
std::queue<int> Q;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=1;i<=a+1;i++) dist[i] = MAX;
	for(int i=1;i<=b;i++)
	{
		int e,f;
		scanf("%d%d",&e,&f);
		V[e].push_back(f+1);
		V[f+1].push_back(e);
	}
	for(int i=d+1;i<=a+1;i++)
	{
		dist[i] = 0;
		Q.push(i);
	}
	while(!Q.empty())
	{
		int k = Q.front();
		Q.pop();
		
		for(int i=0;i<V[k].size();i++)
		{
			if(dist[V[k][i]]==MAX)
			{
				dist[V[k][i]] = dist[k]+1;
				Q.push(V[k][i]);
			}
		}
	}
	
	int ans = MAX;
	for(int i=1;i<=c;i++) ans = ans<dist[i]?ans:dist[i];
	if(ans==MAX) printf("-1");
	else printf("%d",ans);
}
0