結果

問題 No.1190 Points
ユーザー IKyoproIKyopro
提出日時 2020-08-22 14:00:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,433 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 207,016 KB
実行使用メモリ 20,652 KB
最終ジャッジ日時 2024-04-23 08:25:30
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 51 ms
15,616 KB
testcase_04 AC 42 ms
14,080 KB
testcase_05 AC 40 ms
13,056 KB
testcase_06 AC 68 ms
18,560 KB
testcase_07 AC 71 ms
19,584 KB
testcase_08 AC 71 ms
20,612 KB
testcase_09 AC 75 ms
18,968 KB
testcase_10 AC 73 ms
20,552 KB
testcase_11 AC 53 ms
14,468 KB
testcase_12 AC 80 ms
20,252 KB
testcase_13 AC 49 ms
12,416 KB
testcase_14 AC 21 ms
13,568 KB
testcase_15 AC 87 ms
20,292 KB
testcase_16 AC 11 ms
6,944 KB
testcase_17 AC 80 ms
19,464 KB
testcase_18 AC 35 ms
7,808 KB
testcase_19 AC 23 ms
16,640 KB
testcase_20 AC 44 ms
10,240 KB
testcase_21 AC 23 ms
10,752 KB
testcase_22 AC 31 ms
17,280 KB
testcase_23 AC 87 ms
20,652 KB
testcase_24 AC 93 ms
20,644 KB
testcase_25 AC 70 ms
19,584 KB
testcase_26 AC 51 ms
19,300 KB
testcase_27 AC 65 ms
19,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template <class T> using vvvec = vector<vvec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,P;
    cin >> N >> M >> P;
    int S,T;
    cin >> S >> T;
    S--; T--;
    vvec<int> g(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int inf = 1e9+5;
    vvec<int> distS(N,vec<int>(2,inf)),distT(N,vec<int>(2,inf));
    
    auto bfs = [&](int s,vvec<int>& dist)->void{
        queue<pair<int,int>> Q;
        dist[s][0] = 0;
        Q.push({s,0});
        while(!Q.empty()){
            auto [cur,p] = Q.front(); Q.pop();
            for(auto& to:g[cur]){
                if(dist[to][p^1]==inf){
                    dist[to][p^1] = dist[cur][p]+1;
                    Q.push({to,p^1});
                }
            }
        }
    };

    bfs(S,distS);
    bfs(T,distT);

    vec<int> ans;
    for(int i=0;i<N;i++) for(int a=0;a<2;a++) for(int b=0;b<2;b++) if((a+b)%2==P%2){
        if(distS[i][a]+distT[i][b]<=P) ans.push_back(i);
    }
    if(ans.empty()){
        cout << -1 << "\n";
        return 0;
    }
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    cout << ans.size() << "\n";
    for(auto& x:ans) cout << x+1 << "\n";
}
0