結果

問題 No.1190 Points
ユーザー AndrewKAndrewK
提出日時 2020-08-22 11:22:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,398 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 175,524 KB
実行使用メモリ 42,228 KB
最終ジャッジ日時 2024-04-23 07:05:57
合計ジャッジ時間 12,197 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
27,772 KB
testcase_01 AC 22 ms
28,088 KB
testcase_02 AC 16 ms
28,008 KB
testcase_03 AC 309 ms
38,316 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 331 ms
40,896 KB
testcase_07 AC 435 ms
41,812 KB
testcase_08 AC 351 ms
42,228 KB
testcase_09 RE -
testcase_10 AC 365 ms
42,164 KB
testcase_11 RE -
testcase_12 AC 338 ms
42,004 KB
testcase_13 RE -
testcase_14 AC 66 ms
32,240 KB
testcase_15 AC 511 ms
41,780 KB
testcase_16 AC 44 ms
30,080 KB
testcase_17 AC 438 ms
40,564 KB
testcase_18 AC 262 ms
37,416 KB
testcase_19 AC 48 ms
31,000 KB
testcase_20 AC 322 ms
38,436 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 511 ms
42,196 KB
testcase_24 AC 466 ms
41,900 KB
testcase_25 AC 358 ms
41,712 KB
testcase_26 AC 322 ms
41,596 KB
testcase_27 AC 342 ms
41,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, M, P, S, G, u[100001], v[100001];
int kyo_s[100001][2], kyo_g[100001][2];
constexpr int inf = 1000000000;
set<pair<int, int>> st;
queue<pair<int, int>> q;
vector<int> edge[1000001];
vector<int> ans;
int main() {
    cin >> N >> M >> P;
    cin >> S >> G;
    assert(2 <= N && N <= 100000);
    assert(1 <= M && M <= min(N * (N - 1) / 2, 100000));
    assert(1 <= P && P <= 1000000000);
    assert(S != G);
    for (int i = 1; i <= M; i++) {
        cin >> u[i] >> v[i];
        assert(u[i] != v[i]);
        assert(st.count(pair<int, int>(u[i], v[i])) == 0);
        st.insert(pair<int, int>(u[i], v[i]));
        st.insert(pair<int, int>(v[i], u[i]));
        edge[u[i]].push_back(v[i]);
        edge[v[i]].push_back(u[i]);
    }
    for (int i = 1; i <= N; i++) {
        kyo_s[i][0] = inf;
        kyo_s[i][1] = inf;
        kyo_g[i][0] = inf;
        kyo_g[i][1] = inf;
    }
    kyo_s[S][0] = 0;
    q.push(make_pair(0, S));
    while (q.size()) {
        int cnt = q.front().first;
        int x = q.front().second;
        q.pop();
        if (kyo_s[x][cnt % 2] < cnt)
            continue;

        cnt++;

        for (auto &i : edge[x]) {
            if (kyo_s[i][cnt % 2] > cnt) {
                kyo_s[i][cnt % 2] = cnt;
                q.push(make_pair(cnt, i));
            }
        }
    }
    kyo_g[G][0] = 0;
    q.push(make_pair(0, G));
    while (q.size()) {
        int cnt = q.front().first;
        int x = q.front().second;
        q.pop();
        if (kyo_g[x][cnt % 2] < cnt)
            continue;

        cnt++;

        for (auto &i : edge[x]) {
            if (kyo_g[i][cnt % 2] > cnt) {
                kyo_g[i][cnt % 2] = cnt;
                q.push(make_pair(cnt, i));
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        if (P % 2) {
            int odd = min(kyo_s[i][0] + kyo_g[i][1], kyo_s[i][1] + kyo_g[i][0]);
            if (odd <= P) {
                ans.push_back(i);
            }
        } else {
            int even = min(kyo_s[i][0] + kyo_g[i][0], kyo_s[i][1] + kyo_g[i][1]);
            if (even <= P) {
                ans.push_back(i);
            }
        }
    }
    if (ans.size() == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
0