結果

問題 No.1244 Black Segment
ユーザー tempura_pptempura_pp
提出日時 2020-08-08 21:34:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 128,096 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-04-10 05:56:44
合計ジャッジ時間 5,030 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 23 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 23 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 29 ms
7,552 KB
testcase_19 AC 40 ms
7,936 KB
testcase_20 AC 44 ms
8,320 KB
testcase_21 AC 42 ms
8,576 KB
testcase_22 AC 44 ms
8,320 KB
testcase_23 AC 47 ms
8,576 KB
testcase_24 AC 48 ms
8,624 KB
testcase_25 AC 46 ms
8,576 KB
testcase_26 AC 43 ms
8,548 KB
testcase_27 AC 51 ms
9,088 KB
testcase_28 AC 45 ms
8,920 KB
testcase_29 AC 49 ms
8,832 KB
testcase_30 AC 49 ms
8,704 KB
testcase_31 AC 50 ms
8,832 KB
testcase_32 AC 52 ms
8,832 KB
testcase_33 AC 53 ms
8,704 KB
testcase_34 AC 47 ms
8,572 KB
testcase_35 AC 46 ms
9,216 KB
testcase_36 AC 51 ms
9,216 KB
testcase_37 AC 50 ms
9,344 KB
testcase_38 AC 50 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
        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;
}
0