結果

問題 No.1244 Black Segment
ユーザー 沙耶花沙耶花
提出日時 2020-10-02 22:05:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 3,050 ms
コンパイル使用メモリ 209,052 KB
実行使用メモリ 10,060 KB
最終ジャッジ日時 2023-09-24 12:32:24
合計ジャッジ時間 6,200 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 51 ms
5,072 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 51 ms
5,464 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 51 ms
7,716 KB
testcase_19 AC 72 ms
8,336 KB
testcase_20 AC 79 ms
8,968 KB
testcase_21 AC 81 ms
9,088 KB
testcase_22 AC 83 ms
8,892 KB
testcase_23 AC 88 ms
9,084 KB
testcase_24 AC 92 ms
9,088 KB
testcase_25 AC 84 ms
9,408 KB
testcase_26 AC 80 ms
9,004 KB
testcase_27 AC 93 ms
9,604 KB
testcase_28 AC 89 ms
9,496 KB
testcase_29 AC 84 ms
9,284 KB
testcase_30 AC 88 ms
9,496 KB
testcase_31 AC 91 ms
9,352 KB
testcase_32 AC 92 ms
9,380 KB
testcase_33 AC 91 ms
9,244 KB
testcase_34 AC 87 ms
9,404 KB
testcase_35 AC 84 ms
10,060 KB
testcase_36 AC 89 ms
9,928 KB
testcase_37 AC 89 ms
9,880 KB
testcase_38 AC 88 ms
9,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000300

int main(){	

	int N,M,A,B;
	cin>>N>>M>>A>>B;
	vector<pair<int,int>> P(M);
	vector<vector<int>> E(N+1,vector<int>());
	rep(i,M){
		cin>>P[i].second>>P[i].first;
		P[i].second--;
		E[P[i].second].push_back(P[i].first);
		E[P[i].first].push_back(P[i].second);
	}
	
	vector<int> dis(N+1,Inf);
	queue<int> Q;
	rep(i,A){
		dis[i] = 0;
		Q.push(i);
	}
	
	while(Q.size()!=0){
		int u = Q.front();
		Q.pop();
		rep(i,E[u].size()){
			int v = E[u][i];
			if(dis[v]!=Inf)continue;
			dis[v] = dis[u]+1;
			Q.push(v);
		}
	}
	int ans  =Inf;
	for(int i=B;i<dis.size();i++){
		ans = min(ans,dis[i]);
	}

	if(ans==Inf)cout<<-1<<endl;
	else cout<<ans<<endl;
	
    return 0;
}
0