結果

問題 No.1190 Points
ユーザー ktr216ktr216
提出日時 2020-08-22 16:15:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,879 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 173,756 KB
実行使用メモリ 22,392 KB
最終ジャッジ日時 2024-04-23 10:28:10
合計ジャッジ時間 5,903 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,436 KB
testcase_01 AC 3 ms
9,408 KB
testcase_02 AC 3 ms
9,928 KB
testcase_03 AC 94 ms
18,608 KB
testcase_04 AC 79 ms
17,992 KB
testcase_05 AC 75 ms
16,884 KB
testcase_06 AC 134 ms
20,680 KB
testcase_07 AC 140 ms
21,536 KB
testcase_08 AC 165 ms
21,184 KB
testcase_09 AC 159 ms
21,860 KB
testcase_10 AC 159 ms
21,100 KB
testcase_11 AC 121 ms
19,380 KB
testcase_12 AC 161 ms
21,316 KB
testcase_13 AC 111 ms
19,340 KB
testcase_14 AC 28 ms
13,768 KB
testcase_15 AC 184 ms
22,284 KB
testcase_16 AC 21 ms
11,840 KB
testcase_17 AC 168 ms
21,156 KB
testcase_18 AC 84 ms
19,164 KB
testcase_19 AC 18 ms
13,252 KB
testcase_20 AC 115 ms
19,916 KB
testcase_21 AC 41 ms
15,168 KB
testcase_22 AC 47 ms
16,452 KB
testcase_23 AC 183 ms
22,392 KB
testcase_24 AC 185 ms
22,384 KB
testcase_25 AC 145 ms
22,204 KB
testcase_26 AC 101 ms
21,832 KB
testcase_27 AC 153 ms
22,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V =200000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V], d0[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M, P, s, g, u, v;
    cin >> N >> M >> P >> s >> g;
    V = 2 * N;
    s--;
    g--;
    rep(i, M) {
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back({v + N, 1});
        G[v].push_back({u + N, 1});
        G[u + N].push_back({v, 1});
        G[v + N].push_back({u, 1});
    }
    dijkstra(s);
    rep(i, N + N) d0[i] = d[i];
    dijkstra(g);
    vector<int> ans;
    rep(i, N) {
        if (P % 2) {
            ll d1 = d0[i] + d[i + N];
            ll d2 = d0[i + N] + d[i];
            if (d1 <= P || d2 <= P) ans.push_back(i + 1);
        } else {
            ll d1 = d0[i] + d[i];
            ll d2 = d0[i + N] + d[i + N];
            if (d1 <= P || d2 <= P) ans.push_back(i + 1);
        }
    }
    if (ans.size() == 0) {
        cout << "-1\n";
        return 0;
    }
    cout << ans.size() << "\n";
    rep(i, ans.size()) cout << ans[i] << "\n";
    /*
    rep(i, N) {
        cout << d0[i] << " " << d0[i + N] << " " << d[i] << " " << d[i + N] << "\n";
    }
    */
}
0