結果

問題 No.1244 Black Segment
ユーザー ChanyuhChanyuh
提出日時 2020-10-02 22:19:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,966 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 132,584 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-09-24 21:15:32
合計ジャッジ時間 4,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,772 KB
testcase_01 AC 3 ms
5,716 KB
testcase_02 AC 3 ms
5,712 KB
testcase_03 AC 3 ms
5,744 KB
testcase_04 AC 3 ms
5,736 KB
testcase_05 AC 3 ms
5,848 KB
testcase_06 AC 3 ms
5,712 KB
testcase_07 AC 3 ms
5,720 KB
testcase_08 AC 3 ms
5,772 KB
testcase_09 AC 3 ms
5,736 KB
testcase_10 AC 3 ms
5,720 KB
testcase_11 AC 3 ms
5,792 KB
testcase_12 AC 3 ms
5,764 KB
testcase_13 AC 4 ms
5,840 KB
testcase_14 AC 23 ms
7,184 KB
testcase_15 AC 4 ms
5,848 KB
testcase_16 AC 23 ms
7,376 KB
testcase_17 AC 4 ms
5,920 KB
testcase_18 AC 26 ms
8,012 KB
testcase_19 AC 36 ms
8,892 KB
testcase_20 AC 46 ms
9,028 KB
testcase_21 AC 41 ms
9,168 KB
testcase_22 AC 41 ms
8,848 KB
testcase_23 AC 39 ms
8,876 KB
testcase_24 AC 41 ms
8,972 KB
testcase_25 AC 39 ms
9,180 KB
testcase_26 AC 37 ms
8,776 KB
testcase_27 AC 46 ms
9,512 KB
testcase_28 AC 44 ms
9,120 KB
testcase_29 AC 41 ms
8,932 KB
testcase_30 AC 44 ms
9,004 KB
testcase_31 AC 44 ms
9,092 KB
testcase_32 AC 44 ms
9,188 KB
testcase_33 AC 46 ms
9,012 KB
testcase_34 AC 40 ms
8,904 KB
testcase_35 AC 42 ms
9,672 KB
testcase_36 AC 45 ms
9,516 KB
testcase_37 AC 46 ms
9,620 KB
testcase_38 AC 43 ms
9,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

int n,m,a,b;
vector<int> G[100010];
int d[100010];

void solve(){
    cin >> n >> m >> a >> b;
    rep(i,n+1) d[i]=mod;
    rep(i,m){
        int p,q;cin >> p >> q;p--;
        G[p].push_back(q);
        G[q].push_back(p);
    }
    queue<P> que;
    rep(i,a) que.push(P(i,0));
    while(!que.empty()){
        P p=que.front();que.pop();
        int s=p.first;
        if(d[s]<=p.second) continue;
        d[s]=p.second;
        //cout << s << " " << d[s] << endl;
        if(s>=b){
            cout << p.second << endl;
            return;
        }
        for(int t:G[s]){
            if(d[t]<=d[s]+1) continue;
            que.push(P(t,d[s]+1));
        }
    }
    cout << -1 << endl;
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0