結果
| 問題 | 
                            No.1244 Black Segment
                             | 
                    
| コンテスト | |
| ユーザー | 
                             IKyopro
                         | 
                    
| 提出日時 | 2020-10-02 23:53:40 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,125 bytes | 
| コンパイル時間 | 1,887 ms | 
| コンパイル使用メモリ | 202,864 KB | 
| 最終ジャッジ日時 | 2025-01-15 01:28:31 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 RE * 10 | 
ソースコード
#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--;
    vec<int> L(N),R(N);
    vvec<int> g(N+1);
    for(int i=0;i<M;i++){
        cin >> L[i] >> R[i];
        L[i]--,R[i]--;
        int f = max(A,L[i]),t = min(B,R[i])+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";
}
            
            
            
        
            
IKyopro