結果

問題 No.1190 Points
ユーザー srjywrdnprkt
提出日時 2023-01-24 02:53:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 2,145 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 119,012 KB
最終ジャッジ日時 2025-02-10 06:32:32
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    long long N, M, P, S, G, A, B, from, to, alt, d;
    cin >> N >> M >> P >> S >> G;
    S--; G--;
    queue<pair<long long, long long>> que;
    vector<vector<int>> E(N);
    vector<long long> ds0(N, 1e9), ds1(N, 1e9);
    vector<long long> dg0(N, 1e9), dg1(N, 1e9);
    vector<long long> ans;

    for (int i=0; i < M; i++){
        cin >> A >> B;
        A--; B--;
        E[A].push_back(B);
        E[B].push_back(A);
    }

    ds0[S] = 0;
    que.push({S, 0});

    while(!que.empty()){
        tie(from, d) = que.front();
        que.pop();
        for (auto to : E[from]){
            alt = d+1;
            if (alt % 2 == 0 && ds0[to] == 1e9){
                ds0[to] = alt;
                que.push({to, alt});
            }
            else if (alt % 2 == 1 && ds1[to] == 1e9){
                ds1[to] = alt;
                que.push({to, alt});
            }
        }
    }

    dg0[G] = 0;
    que.push({G, 0});

    while(!que.empty()){
        tie(from, d) = que.front();
        que.pop();
        for (auto to : E[from]){
            alt = d+1;
            if (alt % 2 == 0 && dg0[to] == 1e9){
                dg0[to] = alt;
                que.push({to, alt});
            }   
            else if (alt % 2 == 1 && dg1[to] == 1e9){
                dg1[to] = alt;
                que.push({to, alt});
            }   
        }   
    } 

    long long d1, d2;

    for (int i=0; i<N; i++){
        if (P % 2 == 0){
            d1 = P-(ds1[i]+dg1[i]);
            d2 = P-(ds0[i]+dg0[i]);
            if (d1 >= 0 || d2 >= 0) ans.push_back(i+1);
        }
        else{
            d1 = P-(ds1[i]+dg0[i]);
            d2 = P-(ds0[i]+dg1[i]);
            if (d1 >= 0 || d2 >= 0) ans.push_back(i+1);
        }
    }

    if (ans.size() == 0) cout << -1 << endl;
    else{
        cout << ans.size() << endl;
        for (auto x : ans) cout << x << endl;
    }

    return 0;
}
0