結果

問題 No.1244 Black Segment
ユーザー chocopuuchocopuu
提出日時 2020-10-09 20:26:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 207,148 KB
実行使用メモリ 12,360 KB
最終ジャッジ日時 2023-09-27 13:53:06
合計ジャッジ時間 5,694 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 47 ms
7,200 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 48 ms
7,444 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 42 ms
8,824 KB
testcase_19 AC 58 ms
10,248 KB
testcase_20 AC 63 ms
10,632 KB
testcase_21 AC 61 ms
10,992 KB
testcase_22 AC 65 ms
10,664 KB
testcase_23 AC 69 ms
11,036 KB
testcase_24 AC 70 ms
11,204 KB
testcase_25 AC 65 ms
11,308 KB
testcase_26 AC 63 ms
10,580 KB
testcase_27 AC 67 ms
10,900 KB
testcase_28 AC 70 ms
11,368 KB
testcase_29 AC 71 ms
11,248 KB
testcase_30 AC 71 ms
11,160 KB
testcase_31 AC 70 ms
11,028 KB
testcase_32 AC 70 ms
11,028 KB
testcase_33 AC 69 ms
11,104 KB
testcase_34 AC 70 ms
11,252 KB
testcase_35 AC 65 ms
11,436 KB
testcase_36 AC 67 ms
11,304 KB
testcase_37 AC 68 ms
12,360 KB
testcase_38 AC 68 ms
11,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

signed main(){
	int N, M, A, B;
	cin >> N >> M >> A >> B;
	vector<int>l(M), r(M);
	vector<vector<int>>g(N + 1);
	REP(i, M) {
		cin >> l[i] >> r[i];
		--l[i]; --r[i];
		g[l[i]].emplace_back(r[i] + 1);
		g[r[i] + 1].emplace_back(l[i]);
	}
	vector<int>dist(N + 1, INF);
	queue<int>que;
	REP(i, A) {
		dist[i] = 0;
		que.push(i);
	}
	while(que.size()) {
		auto now = que.front();
		que.pop();
		for(auto e: g[now]) {
			if(CHMIN(dist[e], dist[now] + 1)) {
				que.push(e);
			}
		}
	}
	int ans = INF;
	FOR(i, B, N + 1) CHMIN(ans, dist[i]);
	out((ans == INF) ? -1 : ans);
}
0