結果

問題 No.1190 Points
ユーザー Ricky_ponRicky_pon
提出日時 2020-08-22 17:50:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,842 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 208,136 KB
実行使用メモリ 22,460 KB
最終ジャッジ日時 2024-04-23 11:39:25
合計ジャッジ時間 5,760 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 74 ms
16,640 KB
testcase_04 AC 55 ms
15,288 KB
testcase_05 WA -
testcase_06 AC 91 ms
20,096 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 124 ms
21,052 KB
testcase_10 AC 129 ms
21,120 KB
testcase_11 WA -
testcase_12 AC 124 ms
20,948 KB
testcase_13 AC 84 ms
15,432 KB
testcase_14 AC 22 ms
11,392 KB
testcase_15 AC 156 ms
21,968 KB
testcase_16 AC 14 ms
6,912 KB
testcase_17 AC 121 ms
20,560 KB
testcase_18 AC 57 ms
13,572 KB
testcase_19 AC 15 ms
12,544 KB
testcase_20 AC 77 ms
15,080 KB
testcase_21 AC 32 ms
10,880 KB
testcase_22 AC 35 ms
15,488 KB
testcase_23 AC 164 ms
22,460 KB
testcase_24 AC 166 ms
22,324 KB
testcase_25 AC 108 ms
21,888 KB
testcase_26 AC 72 ms
21,232 KB
testcase_27 AC 99 ms
22,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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 (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

template <typename T>
struct edge {
    int from, to;
    T cost;
    edge(int f, int t, T c) : from(f), to(t), cost(c) {}
};

template <typename T>
struct Graph {
    vector<vector<edge<T>>> G;
    int n;

    Graph(int n_) : n(n_) { G.resize(n); }

    void add_edge(int f, int t, T c) { G[f].emplace_back(f, t, c); }
};

template <typename T>
vector<T> dijkstra(Graph<T> &gr, int s) {
    using state = pair<T, int>;
    priority_queue<state, vector<state>, greater<state>> que;
    vector<T> d(gr.n, INF);
    d[s] = 0;
    que.emplace(0, s);
    while (!que.empty()) {
        state p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (edge<T> &e : gr.G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.emplace(d[e.to], e.to);
            }
        }
    }
    return d;
}

int main() {
    int n, m, p;
    scanf("%d%d%d", &n, &m, &p);
    int s, t;
    scanf("%d%d", &s, &t);
    --s;
    --t;
    Graph<lint> gr(2 * n);
    rep(i, m) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a;
        --b;
        gr.add_edge(a, b + n, 1);
        gr.add_edge(a + n, b, 1);
        gr.add_edge(b, a + n, 1);
        gr.add_edge(b + n, a, 1);
    }
    auto ds = dijkstra(gr, s);
    auto dt = dijkstra(gr, t);
    if (ds[t + n * (p % 2)] == INF) {
        puts("-1");
        return 0;
    }
    vector<int> ans;
    rep(i, n) {
        lint tmp = INF;
        if (p % 2 == 0)
            tmp = min(ds[i] + dt[i], ds[i + n] + ds[i + n]);
        else
            tmp = min(ds[i + n] + dt[i], ds[i] + dt[i + n]);
        if (tmp <= p) ans.push_back(i);
    }

    if (ans.empty())
        puts("-1");
    else {
        printf("%d\n", ans.size());
        for (auto v : ans) printf("%d\n", v + 1);
    }
}
0