結果

問題 No.1190 Points
ユーザー ShibuyapShibuyap
提出日時 2020-08-22 16:06:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 2,331 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 204,392 KB
実行使用メモリ 19,624 KB
最終ジャッジ日時 2024-04-23 10:19:58
合計ジャッジ時間 9,673 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,168 KB
testcase_01 AC 7 ms
12,060 KB
testcase_02 AC 6 ms
12,352 KB
testcase_03 AC 210 ms
17,492 KB
testcase_04 AC 155 ms
17,124 KB
testcase_05 AC 192 ms
16,540 KB
testcase_06 AC 223 ms
19,068 KB
testcase_07 AC 312 ms
19,496 KB
testcase_08 AC 386 ms
18,836 KB
testcase_09 AC 365 ms
19,284 KB
testcase_10 AC 385 ms
18,760 KB
testcase_11 AC 263 ms
17,448 KB
testcase_12 AC 365 ms
18,864 KB
testcase_13 AC 244 ms
17,152 KB
testcase_14 AC 35 ms
14,352 KB
testcase_15 AC 417 ms
19,480 KB
testcase_16 AC 28 ms
13,484 KB
testcase_17 AC 378 ms
18,968 KB
testcase_18 AC 160 ms
16,584 KB
testcase_19 AC 25 ms
13,848 KB
testcase_20 AC 211 ms
17,312 KB
testcase_21 AC 71 ms
14,824 KB
testcase_22 AC 64 ms
16,264 KB
testcase_23 AC 436 ms
19,624 KB
testcase_24 AC 420 ms
19,612 KB
testcase_25 AC 224 ms
19,460 KB
testcase_26 AC 130 ms
19,148 KB
testcase_27 AC 225 ms
19,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
struct edge{ int to, cost; };
const int INF = 1001001001;
const int MAX_N = 200005;
const int MAX_V = 200005;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+MAX_V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int ds0[MAX_N], ds1[MAX_N], dg0[MAX_N], dg1[MAX_N];
int main() {
    int n, m, K;
    cin >> n >> m >> K;
    int s, g;
    cin >> s >> g;
    s--, g--;
    rep(i,m){
        int from,to,cost;
        cin >> from >> to;
        from--, to--;
        cost = 1;
        edge e1, e2;
        e1.to = to+100000; e1.cost = cost;
        e2.to = from+100000; e2.cost = cost;
        G[from].push_back(e1);
        G[to].push_back(e2);
        e1.to = to;
        e2.to = from;
        G[from+100000].push_back(e1);
        G[to+100000].push_back(e2);
    }


    dijkstra(s);
    rep(i,MAX_N)ds0[i] = d[i];
    dijkstra(s+100000);
    rep(i,MAX_N)ds1[i] = d[i];
    dijkstra(g);
    rep(i,MAX_N)dg0[i] = d[i];
    dijkstra(g+100000);
    rep(i,MAX_N)dg1[i] = d[i];

    vector<int> ans;

    rep(i,n){
        int x,flag = 0;
        x = ds0[i] + dg0[i];
        if(x <= K && (K-x)%2==0)flag = 1;
        x = ds0[i] + dg1[i];
        if(x <= K && (K-x)%2==0)flag = 1;
        x = ds1[i] + dg0[i];
        if(x <= K && (K-x)%2==0)flag = 1;
        x = ds1[i] + dg1[i];
        if(x <= K && (K-x)%2==0)flag = 1;
        if(flag)ans.push_back(i+1);
    }

    if(ans.size()==0){
        cout << -1 << endl;
    }else{
        cout << ans.size() << endl;
        rep(i,ans.size()){
            cout << ans[i] << endl;
        }
    }
    return 0;
}

0