結果
| 問題 | 
                            No.1244 Black Segment
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tempura_pp
                         | 
                    
| 提出日時 | 2020-08-08 21:35:32 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,221 bytes | 
| コンパイル時間 | 1,795 ms | 
| コンパイル使用メモリ | 122,540 KB | 
| 最終ジャッジ日時 | 2025-01-12 18:55:58 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | AC * 24 WA * 12 | 
ソースコード
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    vector<vector<int>> v(n+1);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        assert(x<=y);
        --x;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vector<int> dist(n+1,inf);
    queue<int> q;
    rep(i,a+1){
        dist[i] = 0;
        q.push(i);
    }
    while(q.size()){
        int x=q.front();q.pop();
        for(auto to : v[x]){
            if(dist[to]==inf){
                dist[to]=dist[x]+1;
                q.push(to);
            }
        }
    }
    int ans=inf;
    REP(i,b,n+1)ans=min(ans,dist[i]);
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}
            
            
            
        
            
tempura_pp