結果

問題 No.1244 Black Segment
ユーザー finefine
提出日時 2020-10-03 01:00:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 172,028 KB
実行使用メモリ 9,292 KB
最終ジャッジ日時 2023-09-25 01:51:35
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 21 ms
4,820 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 21 ms
4,932 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 29 ms
7,264 KB
testcase_19 AC 40 ms
7,740 KB
testcase_20 AC 46 ms
8,392 KB
testcase_21 AC 40 ms
8,336 KB
testcase_22 AC 43 ms
8,068 KB
testcase_23 AC 48 ms
8,332 KB
testcase_24 AC 48 ms
8,676 KB
testcase_25 AC 47 ms
8,596 KB
testcase_26 AC 44 ms
8,288 KB
testcase_27 AC 51 ms
8,856 KB
testcase_28 AC 48 ms
8,552 KB
testcase_29 AC 42 ms
8,528 KB
testcase_30 AC 46 ms
8,544 KB
testcase_31 AC 47 ms
8,656 KB
testcase_32 AC 47 ms
8,600 KB
testcase_33 AC 45 ms
8,596 KB
testcase_34 AC 45 ms
8,756 KB
testcase_35 AC 43 ms
9,024 KB
testcase_36 AC 46 ms
9,292 KB
testcase_37 AC 46 ms
9,064 KB
testcase_38 AC 47 ms
8,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m, a, b;
    cin >> n >> m >> a >> b;
    --a;

    vector< vector<int> > g(n + 1);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        --l;
        g[l].push_back(r);
        g[r].push_back(l);
    }

    queue<int> q;
    vector<int> d(n + 1, -1);
    for (int i = 0; i <= a; i++) {
        d[i] = 0;
        q.push(i);
    }

    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (int nex : g[cur]) {
            if (d[nex] != -1) continue;
            d[nex] = d[cur] + 1;
            q.push(nex);
        }
    }

    int ans = 1e9;
    for (int i = b; i <= n; i++) {
        ans = min(ans, (d[i] == -1 ? 1000000000 : d[i]));
    }
    cout << (ans >= 1000000000 ? -1 : ans) << newl;
    return 0;
}
0