結果

問題 No.1190 Points
ユーザー rogi52rogi52
提出日時 2022-10-21 01:58:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,693 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 208,884 KB
実行使用メモリ 17,244 KB
最終ジャッジ日時 2023-09-13 05:38:54
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 88 ms
13,092 KB
testcase_04 AC 72 ms
12,128 KB
testcase_05 AC 68 ms
11,216 KB
testcase_06 AC 117 ms
15,712 KB
testcase_07 AC 128 ms
16,812 KB
testcase_08 AC 136 ms
16,228 KB
testcase_09 AC 139 ms
15,892 KB
testcase_10 AC 136 ms
16,208 KB
testcase_11 AC 99 ms
12,596 KB
testcase_12 AC 143 ms
16,212 KB
testcase_13 AC 99 ms
11,456 KB
testcase_14 AC 21 ms
9,712 KB
testcase_15 AC 171 ms
16,716 KB
testcase_16 AC 15 ms
5,540 KB
testcase_17 AC 152 ms
15,916 KB
testcase_18 AC 57 ms
9,052 KB
testcase_19 AC 16 ms
10,704 KB
testcase_20 AC 81 ms
10,652 KB
testcase_21 AC 35 ms
8,848 KB
testcase_22 AC 34 ms
12,624 KB
testcase_23 AC 182 ms
17,096 KB
testcase_24 AC 180 ms
17,244 KB
testcase_25 AC 117 ms
16,768 KB
testcase_26 AC 70 ms
16,124 KB
testcase_27 AC 122 ms
16,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// g <- pair < v , cost > 
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
    T INF = numeric_limits< T >::max();
    vector<T> dist(graph.size(), INF);
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
    q.push({dist[s] = T(0), s});
    while(!q.empty()){
        auto [uc, ui] = q.top(); q.pop();
        if(uc != dist[ui]) continue;
        for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) 
            q.push({dist[vi] = uc + vc, vi});
    }
    return dist;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M,P; cin >> N >> M >> P;
    int S,G; cin >> S >> G; S--; G--;
    vector<vector<pair<int,int>>> H(N * 2);
    auto h = [&](int v, int p) { return v * 2 + p; };
    rep(_,M) {
        int u,v; cin >> u >> v; u--; v--;
        for(int p : {0, 1}) {
            H[h(u, p)].push_back({h(v, 1 - p), 1});
            H[h(v, p)].push_back({h(u, 1 - p), 1});
        }
    }

    auto distS = dijkstra(H, h(S, 0));
    auto distG = dijkstra(H, h(G, 0));
    vector<int> ans;
    int INF = numeric_limits<int>::max();
    rep(i,N) {
        int ok = 0;
        for(int ps : {0, 1}) for(int pg : {0, 1}) {
            int ds = distS[h(i, ps)];
            int dg = distG[h(i, pg)];
            ok |= (ds != INF && dg != INF && ds + dg <= P && (ds + dg) % 2 == P % 2);
        }
        if(ok) ans.push_back(i);
    }

    if(ans.empty()) {
        cout << -1 << "\n";
    } else {
        cout << ans.size() << "\n";
        for(int a : ans) cout << a + 1 << "\n";
    }
}
0