結果

問題 No.1244 Black Segment
ユーザー 👑 NachiaNachia
提出日時 2020-10-02 21:55:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 880 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 172,080 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2023-09-23 04:53:05
合計ジャッジ時間 6,161 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,716 KB
testcase_01 AC 4 ms
5,708 KB
testcase_02 AC 4 ms
5,912 KB
testcase_03 AC 4 ms
5,716 KB
testcase_04 AC 3 ms
5,892 KB
testcase_05 AC 3 ms
5,716 KB
testcase_06 AC 4 ms
5,712 KB
testcase_07 AC 3 ms
5,716 KB
testcase_08 AC 3 ms
5,764 KB
testcase_09 AC 3 ms
5,756 KB
testcase_10 AC 3 ms
5,716 KB
testcase_11 AC 4 ms
5,716 KB
testcase_12 AC 4 ms
5,708 KB
testcase_13 AC 5 ms
6,016 KB
testcase_14 AC 53 ms
7,036 KB
testcase_15 AC 5 ms
6,088 KB
testcase_16 AC 53 ms
7,360 KB
testcase_17 AC 5 ms
5,944 KB
testcase_18 AC 54 ms
8,008 KB
testcase_19 AC 75 ms
8,516 KB
testcase_20 AC 81 ms
8,868 KB
testcase_21 AC 79 ms
8,784 KB
testcase_22 AC 78 ms
8,744 KB
testcase_23 AC 82 ms
8,896 KB
testcase_24 AC 88 ms
8,868 KB
testcase_25 AC 83 ms
8,884 KB
testcase_26 AC 82 ms
8,764 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N, M;
int A, B;
vector<int> nx[100000];
int dp[100000];

const int INF = 100000000;

int main() {
    cin >> N >> M;
    cin >> A >> B; A--; B--;
    rep(i, M) {
        int l, r; cin >> l >> r; l--;
        nx[l].push_back(r);
        nx[r].push_back(l);
    }

    rep(i, N + 1) dp[i] = INF;
    rep(i, A + 1) dp[i] = 0;
    queue<int> Q; rep(i, A + 1) Q.push(i);
    while (Q.size()) {
        int p = Q.front(); Q.pop();
        for (int v : nx[p]) {
            if (dp[v] < INF) continue;
            dp[v] = dp[p] + 1;
            Q.push(v);
        }
    }

    int ans = INF;
    for (int i = B + 1; i <= N; i++) ans = min(ans, dp[i]);
    if (ans >= INF / 2) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}
0