結果

問題 No.1244 Black Segment
ユーザー chocopuuchocopuu
提出日時 2020-10-09 20:25:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,421 bytes
コンパイル時間 6,091 ms
コンパイル使用メモリ 265,652 KB
実行使用メモリ 12,320 KB
最終ジャッジ日時 2023-09-27 13:52:58
合計ジャッジ時間 8,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 55 ms
7,344 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 55 ms
7,448 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 53 ms
8,940 KB
testcase_19 AC 75 ms
10,252 KB
testcase_20 AC 88 ms
10,956 KB
testcase_21 AC 84 ms
11,100 KB
testcase_22 AC 88 ms
10,744 KB
testcase_23 AC 92 ms
10,964 KB
testcase_24 AC 94 ms
11,308 KB
testcase_25 AC 91 ms
11,304 KB
testcase_26 AC 87 ms
10,644 KB
testcase_27 AC 94 ms
10,904 KB
testcase_28 AC 92 ms
11,432 KB
testcase_29 AC 95 ms
11,232 KB
testcase_30 AC 96 ms
11,204 KB
testcase_31 AC 92 ms
10,980 KB
testcase_32 AC 97 ms
10,940 KB
testcase_33 AC 97 ms
11,132 KB
testcase_34 AC 91 ms
11,272 KB
testcase_35 AC 88 ms
11,392 KB
testcase_36 AC 85 ms
11,272 KB
testcase_37 AC 91 ms
12,320 KB
testcase_38 AC 96 ms
12,016 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