結果

問題 No.1190 Points
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-08-25 03:31:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 482 ms / 2,000 ms
コード長 2,348 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 179,080 KB
実行使用メモリ 37,716 KB
最終ジャッジ日時 2024-04-24 04:07:21
合計ジャッジ時間 9,611 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 208 ms
27,392 KB
testcase_04 AC 174 ms
24,576 KB
testcase_05 AC 206 ms
22,400 KB
testcase_06 AC 248 ms
33,792 KB
testcase_07 AC 334 ms
35,840 KB
testcase_08 AC 334 ms
35,200 KB
testcase_09 AC 348 ms
34,884 KB
testcase_10 AC 335 ms
35,072 KB
testcase_11 AC 245 ms
27,524 KB
testcase_12 AC 328 ms
35,072 KB
testcase_13 AC 233 ms
25,124 KB
testcase_14 AC 45 ms
17,536 KB
testcase_15 AC 435 ms
36,880 KB
testcase_16 AC 26 ms
9,088 KB
testcase_17 AC 377 ms
34,144 KB
testcase_18 AC 169 ms
22,196 KB
testcase_19 AC 40 ms
18,816 KB
testcase_20 AC 220 ms
24,968 KB
testcase_21 AC 85 ms
16,640 KB
testcase_22 AC 105 ms
25,088 KB
testcase_23 AC 447 ms
37,716 KB
testcase_24 AC 482 ms
37,560 KB
testcase_25 AC 316 ms
37,248 KB
testcase_26 AC 261 ms
36,480 KB
testcase_27 AC 325 ms
37,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.25 03:31:17
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;




template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();
    
    
    vector<T> d; 
    Dijkstra(int V) : V(V) {
        G.resize(V);
    }
    
    
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }
    void build(int s) {
        d.assign(V, inf); 
        typedef tuple<T, int> P; 
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s] = 0; 
        pq.push(P(d[s], s)); 
        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = get<1>(p);
            
            if (d[v] < get<0>(p)) continue; 
            for (const edge &e : G[v])
            {
                
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    pq.push(P(d[e.to], e.to));
                }
            }
        }
    }
};
int main() {
    int n,m,p;cin >> n >> m >> p;
    int s,g;cin >> s >> g;
    s--;g--;
    Dijkstra<ll> G1(n+n),G2(n+n);
    for (int i = 0; i < m; i++) {
        int u,v;cin >> u >> v;
        u--;
        v--;
        G1.add_edge(u,n+v,1);
        G1.add_edge(n+u,v,1);
        G2.add_edge(u,n+v,1);
        G2.add_edge(n+u,v,1);
    }
    G1.build(s);
    G2.build(g);
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        if (p & 1) {
            if ((G1.d[i] != G1.inf && G2.d[i+n] != G2.inf && G1.d[i] + G2.d[i+n] <= p) 
            || (G1.d[i+n] != G1.inf && G2.d[i] != G2.inf && G1.d[i+n] + G2.d[i] <= p)) {
                ans.push_back(i+1);
            }
        }
        else {
            if ((G1.d[i] != G1.inf && G2.d[i] != G2.inf && G1.d[i] + G2.d[i] <= p) 
            || (G1.d[i+n] != G1.inf && G2.d[i+n] != G2.inf && G1.d[i+n] + G2.d[i+n] <= p)) {
                ans.push_back(i+1);
            }
        }
    }
    if (ans.size() == 0) {
        puts("-1");
        return 0;
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
0