結果

問題 No.1190 Points
ユーザー IKyoproIKyopro
提出日時 2020-08-22 14:00:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,433 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 211,012 KB
実行使用メモリ 20,492 KB
最終ジャッジ日時 2023-08-05 11:09:54
合計ジャッジ時間 5,282 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 59 ms
15,244 KB
testcase_04 AC 46 ms
14,124 KB
testcase_05 AC 43 ms
12,944 KB
testcase_06 AC 70 ms
18,312 KB
testcase_07 AC 82 ms
19,620 KB
testcase_08 AC 79 ms
20,492 KB
testcase_09 AC 88 ms
18,632 KB
testcase_10 AC 85 ms
20,312 KB
testcase_11 AC 58 ms
14,240 KB
testcase_12 AC 86 ms
19,916 KB
testcase_13 AC 51 ms
12,260 KB
testcase_14 AC 24 ms
13,084 KB
testcase_15 AC 94 ms
19,812 KB
testcase_16 AC 12 ms
6,164 KB
testcase_17 AC 86 ms
19,068 KB
testcase_18 AC 34 ms
7,780 KB
testcase_19 AC 23 ms
16,504 KB
testcase_20 AC 45 ms
10,236 KB
testcase_21 AC 25 ms
10,936 KB
testcase_22 AC 34 ms
16,984 KB
testcase_23 AC 98 ms
20,244 KB
testcase_24 AC 94 ms
20,236 KB
testcase_25 AC 68 ms
19,344 KB
testcase_26 AC 52 ms
19,152 KB
testcase_27 AC 70 ms
19,412 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