結果

問題 No.1244 Black Segment
ユーザー 👑 tute7627tute7627
提出日時 2020-02-11 04:16:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 173,696 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-04-17 02:07:50
合計ジャッジ時間 6,410 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 57 ms
5,888 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 56 ms
5,504 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 54 ms
7,552 KB
testcase_19 AC 83 ms
8,448 KB
testcase_20 AC 92 ms
8,704 KB
testcase_21 AC 87 ms
8,832 KB
testcase_22 AC 92 ms
8,576 KB
testcase_23 AC 96 ms
8,704 KB
testcase_24 AC 98 ms
8,832 KB
testcase_25 AC 96 ms
8,960 KB
testcase_26 AC 93 ms
8,704 KB
testcase_27 AC 102 ms
9,088 KB
testcase_28 AC 97 ms
9,344 KB
testcase_29 AC 98 ms
8,960 KB
testcase_30 AC 97 ms
9,088 KB
testcase_31 AC 101 ms
8,832 KB
testcase_32 AC 99 ms
8,960 KB
testcase_33 AC 97 ms
8,960 KB
testcase_34 AC 98 ms
9,088 KB
testcase_35 AC 89 ms
9,856 KB
testcase_36 AC 97 ms
9,600 KB
testcase_37 AC 96 ms
10,240 KB
testcase_38 AC 94 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define rep(i,n,m) for(int i = (n); i < (int)(m); i++)
#define rrep(i,n,m) for(int i = (m) - 1; i >= (int)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e9+1;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
int main(){
	int n,m,a,b;cin>>n>>m>>a>>b;
	a--;b--;
	vector<vector<int>>g(n+1);
	rep(i,0,m){
		int l,r;
		cin>>l>>r;
		l--;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	queue<pair<int,int>>que;
	vector<int>dist(n+1,INF);
	rep(i,0,a+1)que.emplace(i,0);
	while(!que.empty()){
		auto now=que.front();
		que.pop();
		if(dist[now.first]!=INF)continue;
		dist[now.first]=now.second;
		for(auto to:g[now.first]){
			que.emplace(to,now.second+1);
		}
	}
	int res=INF;
	rep(i,b+1,n+1)chmin(res,dist[i]);
	if(res!=INF)cout<<res<<endl;
	else cout<<-1<<endl;
  return 0;
}
0