結果

問題 No.1190 Points
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-24 02:53:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 2,145 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 120,956 KB
実行使用メモリ 12,920 KB
最終ジャッジ日時 2023-09-08 02:25:19
合計ジャッジ時間 8,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 111 ms
9,800 KB
testcase_04 AC 71 ms
9,100 KB
testcase_05 AC 126 ms
8,620 KB
testcase_06 AC 94 ms
10,920 KB
testcase_07 AC 178 ms
12,176 KB
testcase_08 AC 223 ms
12,592 KB
testcase_09 AC 212 ms
11,904 KB
testcase_10 AC 224 ms
12,600 KB
testcase_11 AC 149 ms
9,524 KB
testcase_12 AC 205 ms
12,396 KB
testcase_13 AC 132 ms
8,764 KB
testcase_14 AC 24 ms
7,732 KB
testcase_15 AC 210 ms
12,476 KB
testcase_16 AC 14 ms
4,524 KB
testcase_17 AC 184 ms
11,996 KB
testcase_18 AC 86 ms
6,196 KB
testcase_19 AC 18 ms
9,068 KB
testcase_20 AC 115 ms
7,632 KB
testcase_21 AC 32 ms
6,932 KB
testcase_22 AC 41 ms
9,788 KB
testcase_23 AC 215 ms
12,920 KB
testcase_24 AC 222 ms
12,668 KB
testcase_25 AC 97 ms
11,928 KB
testcase_26 AC 84 ms
11,212 KB
testcase_27 AC 91 ms
11,700 KB
権限があれば一括ダウンロードができます

ソースコード

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