結果

問題 No.1190 Points
ユーザー Ricky_ponRicky_pon
提出日時 2020-08-22 17:53:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 2,760 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 207,748 KB
実行使用メモリ 22,464 KB
最終ジャッジ日時 2024-04-23 11:45:13
合計ジャッジ時間 6,273 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 77 ms
16,640 KB
testcase_04 AC 59 ms
15,232 KB
testcase_05 AC 54 ms
14,080 KB
testcase_06 AC 93 ms
20,096 KB
testcase_07 AC 113 ms
21,376 KB
testcase_08 AC 121 ms
21,120 KB
testcase_09 AC 119 ms
21,052 KB
testcase_10 AC 124 ms
21,120 KB
testcase_11 AC 91 ms
17,004 KB
testcase_12 AC 125 ms
21,120 KB
testcase_13 AC 83 ms
15,432 KB
testcase_14 AC 19 ms
11,520 KB
testcase_15 AC 148 ms
21,964 KB
testcase_16 AC 14 ms
6,528 KB
testcase_17 AC 133 ms
20,428 KB
testcase_18 AC 61 ms
13,572 KB
testcase_19 AC 16 ms
12,544 KB
testcase_20 AC 77 ms
15,080 KB
testcase_21 AC 30 ms
10,880 KB
testcase_22 AC 36 ms
15,488 KB
testcase_23 AC 156 ms
22,464 KB
testcase_24 AC 158 ms
22,324 KB
testcase_25 AC 106 ms
22,016 KB
testcase_26 AC 68 ms
21,376 KB
testcase_27 AC 113 ms
21,888 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);
    vector<int> ans;
    rep(i, n) {
        lint tmp = INF;
        if (p % 2 == 0)
            tmp = min(ds[i] + dt[i], ds[i + n] + dt[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