結果

問題 No.1244 Black Segment
ユーザー RubikunRubikun
提出日時 2020-10-02 22:15:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 172,104 KB
実行使用メモリ 9,400 KB
最終ジャッジ日時 2023-09-24 21:04:47
合計ジャッジ時間 4,540 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,136 KB
testcase_01 AC 4 ms
6,024 KB
testcase_02 AC 4 ms
6,064 KB
testcase_03 AC 4 ms
6,076 KB
testcase_04 AC 3 ms
6,272 KB
testcase_05 AC 4 ms
6,032 KB
testcase_06 AC 4 ms
6,068 KB
testcase_07 AC 4 ms
6,024 KB
testcase_08 AC 4 ms
6,052 KB
testcase_09 AC 4 ms
6,132 KB
testcase_10 AC 4 ms
6,032 KB
testcase_11 AC 4 ms
6,068 KB
testcase_12 AC 4 ms
6,272 KB
testcase_13 AC 5 ms
6,168 KB
testcase_14 AC 23 ms
7,408 KB
testcase_15 AC 5 ms
6,228 KB
testcase_16 AC 23 ms
7,504 KB
testcase_17 AC 5 ms
6,176 KB
testcase_18 AC 24 ms
7,988 KB
testcase_19 AC 38 ms
8,548 KB
testcase_20 AC 40 ms
8,824 KB
testcase_21 AC 41 ms
8,972 KB
testcase_22 AC 43 ms
8,660 KB
testcase_23 AC 43 ms
8,740 KB
testcase_24 AC 41 ms
8,884 KB
testcase_25 AC 45 ms
8,920 KB
testcase_26 AC 44 ms
8,744 KB
testcase_27 AC 43 ms
9,184 KB
testcase_28 AC 43 ms
8,936 KB
testcase_29 AC 45 ms
8,900 KB
testcase_30 AC 49 ms
8,912 KB
testcase_31 AC 47 ms
8,912 KB
testcase_32 AC 47 ms
8,976 KB
testcase_33 AC 48 ms
8,980 KB
testcase_34 AC 45 ms
8,844 KB
testcase_35 AC 44 ms
9,356 KB
testcase_36 AC 49 ms
9,400 KB
testcase_37 AC 43 ms
9,348 KB
testcase_38 AC 43 ms
9,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;

vector<int> G[MAX];
int dis[MAX];
int A,B;

void BFS(){
    for(int i=0;i<MAX;i++) dis[i]=INF;
    queue<int> Q;
    
    for(int i=0;i<=A;i++){
        dis[i]=0;
        Q.push(i);
    }
    
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(int to:G[u]){
            if(chmin(dis[to],dis[u]+1)){
                Q.push(to);
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M>>A>>B;
    A--;B--;
    
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b+1);
        G[b+1].push_back(a);
    }
    
    BFS();
    
    int ans=INF;
    for(int i=B+1;i<MAX;i++) chmin(ans,dis[i]);
    
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
    
}

0