結果

問題 No.1190 Points
ユーザー やむなくやむなく
提出日時 2020-08-22 15:26:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 2,437 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 176,764 KB
実行使用メモリ 20,176 KB
最終ジャッジ日時 2024-04-23 09:46:06
合計ジャッジ時間 7,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 147 ms
15,616 KB
testcase_04 AC 99 ms
14,080 KB
testcase_05 AC 157 ms
13,184 KB
testcase_06 AC 142 ms
18,432 KB
testcase_07 AC 224 ms
19,840 KB
testcase_08 AC 263 ms
20,176 KB
testcase_09 AC 257 ms
18,432 KB
testcase_10 AC 265 ms
20,096 KB
testcase_11 AC 177 ms
14,208 KB
testcase_12 AC 255 ms
19,840 KB
testcase_13 AC 159 ms
12,160 KB
testcase_14 AC 37 ms
13,312 KB
testcase_15 AC 275 ms
19,584 KB
testcase_16 AC 21 ms
6,400 KB
testcase_17 AC 246 ms
18,944 KB
testcase_18 AC 98 ms
7,680 KB
testcase_19 AC 35 ms
16,768 KB
testcase_20 AC 146 ms
10,240 KB
testcase_21 AC 45 ms
10,880 KB
testcase_22 AC 63 ms
17,536 KB
testcase_23 AC 280 ms
20,052 KB
testcase_24 AC 287 ms
20,096 KB
testcase_25 AC 142 ms
19,584 KB
testcase_26 AC 115 ms
19,328 KB
testcase_27 AC 139 ms
19,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by yamunaku on 2020/08/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n, m, d;
    cin >> n >> m >> d;
    int s, g;
    cin >> s >> g;
    s--, g--;
    mti e(n);
    rep(i, m){
        int u, v;
        cin >> u >> v;
        u--, v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    mti ds(n, vi(2, IINF));
    mti dg(n, vi(2, IINF));
    queue<pair<int, int>> bfs;
    ds[s][0] = 0;
    bfs.emplace(s, 0);
    while(!bfs.empty()){
        auto p = bfs.front();
        bfs.pop();
        for(auto &nx : e[p.first]){
            if(ds[nx][p.second ^ 1] != IINF) continue;
            ds[nx][p.second ^ 1] = ds[p.first][p.second] + 1;
            bfs.emplace(nx, p.second ^ 1);
        }
    }
    dg[g][0] = 0;
    bfs.emplace(g, 0);
    while(!bfs.empty()){
        auto p = bfs.front();
        bfs.pop();
        for(auto &nx : e[p.first]){
            if(dg[nx][p.second ^ 1] != IINF) continue;
            dg[nx][p.second ^ 1] = dg[p.first][p.second] + 1;
            bfs.emplace(nx, p.second ^ 1);
        }
    }
    vector<int> ans;
    rep(i, n){
        rep(x, 2){
            rep(y, 2){
                int dd = ds[i][x] + dg[i][y];
                if(dd <= d && dd % 2 == d % 2){
                    ans.push_back(i);
                    goto next;
                }
            }
        }
        next:;
    }
    if(ans.size() == 0){
        cout << -1 << endl;
        return 0;
    }
    sort(all(ans));
    cout << ans.size() << endl;
    for(auto &x : ans){
        cout << x + 1 << endl;
    }
    return 0;
}
0