結果

問題 No.1244 Black Segment
ユーザー IKyoproIKyopro
提出日時 2020-10-02 23:55:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 2,756 ms
コンパイル使用メモリ 206,336 KB
実行使用メモリ 9,676 KB
最終ジャッジ日時 2023-09-25 00:16:37
合計ジャッジ時間 5,224 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 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 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 21 ms
4,648 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 21 ms
4,476 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 25 ms
7,196 KB
testcase_19 AC 34 ms
7,276 KB
testcase_20 AC 37 ms
7,940 KB
testcase_21 AC 42 ms
8,388 KB
testcase_22 AC 44 ms
8,000 KB
testcase_23 AC 47 ms
8,344 KB
testcase_24 AC 47 ms
8,412 KB
testcase_25 AC 46 ms
8,516 KB
testcase_26 AC 42 ms
8,556 KB
testcase_27 AC 54 ms
8,824 KB
testcase_28 AC 48 ms
8,600 KB
testcase_29 AC 50 ms
8,540 KB
testcase_30 AC 46 ms
8,588 KB
testcase_31 AC 51 ms
8,796 KB
testcase_32 AC 54 ms
8,528 KB
testcase_33 AC 54 ms
8,264 KB
testcase_34 AC 38 ms
8,292 KB
testcase_35 AC 41 ms
9,676 KB
testcase_36 AC 44 ms
9,376 KB
testcase_37 AC 40 ms
7,896 KB
testcase_38 AC 39 ms
7,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,A,B;
    cin >> N >> M >> A >> B;
    A--,B--;
    vvec<int> g(N+1);
    for(int i=0;i<M;i++){
        int l,r;
        cin >> l >> r;
        l--,r--;
        int f = max(A,l),t = min(B,r)+1;
        g[f].push_back(t);
        g[t].push_back(f);
    }
    int inf = 1e9;
    vec<int> dp(N+1,inf);
    dp[A] = 0;
    queue<int> Q;
    Q.push(A);
    while(!Q.empty()){
        int cur = Q.front(); Q.pop();
        for(auto& to:g[cur]){
            if(dp[to]==inf){
                dp[to] = dp[cur]+1;
                Q.push(to);
            }
        }
    }
    cout << (dp[B+1]==inf? -1:dp[B+1]) << "\n";
}
0