結果

問題 No.1190 Points
ユーザー hedwig100hedwig100
提出日時 2020-08-22 19:31:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 2,094 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 172,404 KB
実行使用メモリ 16,300 KB
最終ジャッジ日時 2024-04-23 12:16:48
合計ジャッジ時間 5,144 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 63 ms
12,672 KB
testcase_04 AC 52 ms
11,492 KB
testcase_05 AC 47 ms
10,816 KB
testcase_06 AC 89 ms
14,976 KB
testcase_07 AC 128 ms
15,936 KB
testcase_08 AC 83 ms
16,228 KB
testcase_09 AC 82 ms
14,976 KB
testcase_10 AC 88 ms
16,300 KB
testcase_11 AC 57 ms
11,820 KB
testcase_12 AC 90 ms
15,784 KB
testcase_13 AC 61 ms
10,368 KB
testcase_14 AC 23 ms
9,808 KB
testcase_15 AC 118 ms
15,232 KB
testcase_16 AC 12 ms
5,504 KB
testcase_17 AC 98 ms
14,720 KB
testcase_18 AC 40 ms
7,552 KB
testcase_19 AC 17 ms
10,984 KB
testcase_20 AC 53 ms
9,216 KB
testcase_21 AC 27 ms
8,576 KB
testcase_22 AC 39 ms
12,680 KB
testcase_23 AC 114 ms
15,744 KB
testcase_24 AC 114 ms
15,744 KB
testcase_25 AC 92 ms
15,232 KB
testcase_26 AC 77 ms
15,104 KB
testcase_27 AC 89 ms
15,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int N;
vector<int> bfs(vector<vector<int>> &G,int s) {
    vector<int> dist(2*N,-1);
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int e:G[v]) {
            if (dist[e] >= 0) continue;
            dist[e] = dist[v] + 1;
            q.push(e);
        }
    }
    return dist;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int M,P,s,g; cin >> N >> M >> P >> s >> g;
    --s; --g;
    vector<vector<int>> G(2*N);
    rep(i,M) {
        int a,b; cin >> a >> b;
        --a; --b;
        G[a].push_back(b + N);
        G[b + N].push_back(a);
        G[b].push_back(a + N);
        G[a + N].push_back(b);
    }

    vector<int> dist1 = bfs(G,s);
    vector<int> dist2 = bfs(G,g);
    vector<int> ans;

    auto judge = [&](int a,int b) {
        return (dist1[a] >= 0 && dist2[b] >= 0 && dist1[a] + dist2[b] <= P);
    };
    rep(i,N) {
        if (i == s || i == g) {
            if (P%2 == 0 && dist1[g] >= 0 && dist1[g] <= P) {
                ans.push_back(i + 1);
            }
            if (P%2 == 1 && dist1[g + N] >= 0 && dist1[g + N] <= P) {
                ans.push_back(i + 1); 
            }
            continue;
        }
        bool flag = false;
        if (P%2 == 0) {
            if (judge(i,i) || judge(i + N,i + N)) flag = true;
        } else {
            if (judge(i,i + N) || judge(i + N,i)) flag = true;
        }
        if (flag) ans.push_back(i + 1);
    }
    if ((int)ans.size() == 0) {
        cout << -1 << '\n';
        return 0;
    }
    cout << ans.size() << '\n';
    rep(i,ans.size()) cout << ans[i] << '\n';
    return 0;
}
0