結果

問題 No.1244 Black Segment
ユーザー rniyarniya
提出日時 2020-10-02 22:21:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 171,728 KB
実行使用メモリ 8,796 KB
最終ジャッジ日時 2023-09-24 21:19:19
合計ジャッジ時間 4,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 20 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 21 ms
6,616 KB
testcase_19 AC 29 ms
6,784 KB
testcase_20 AC 31 ms
7,400 KB
testcase_21 AC 31 ms
7,776 KB
testcase_22 AC 32 ms
7,552 KB
testcase_23 AC 36 ms
7,832 KB
testcase_24 AC 32 ms
7,628 KB
testcase_25 AC 31 ms
7,472 KB
testcase_26 AC 33 ms
8,008 KB
testcase_27 AC 45 ms
8,796 KB
testcase_28 AC 35 ms
8,000 KB
testcase_29 AC 36 ms
8,252 KB
testcase_30 AC 33 ms
7,724 KB
testcase_31 AC 39 ms
8,252 KB
testcase_32 AC 44 ms
8,340 KB
testcase_33 AC 41 ms
8,240 KB
testcase_34 AC 21 ms
6,632 KB
testcase_35 AC 22 ms
6,840 KB
testcase_36 AC 27 ms
7,464 KB
testcase_37 AC 32 ms
7,700 KB
testcase_38 AC 32 ms
7,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,A,B; cin >> N >> M >> A >> B; --A,B;
    vector<vector<int>> G(N+1);
    for (int i=0;i<M;++i){
        int L,R; cin >> L >> R; --L;
        L=max(L,A); L=min(L,B);
        R=max(R,A); R=min(R,B);
        G[L].emplace_back(R);
        G[R].emplace_back(L);
    }

    queue<int> que;
    vector<int> dp(N+2,INF);
    dp[A]=0; que.emplace(A);
    while(!que.empty()){
        int v=que.front(); que.pop();
        for (int u:G[v]){
            if (dp[v]+1<dp[u]){
                dp[u]=dp[v]+1;
                que.emplace(u);
            }
        }
    }

    cout << (dp[B]==INF?-1:dp[B]) << '\n';
}
0