結果

問題 No.1190 Points
ユーザー hedwig100hedwig100
提出日時 2020-08-22 18:37:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,093 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 172,528 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-04-23 12:08:38
合計ジャッジ時間 4,139 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 16 ms
9,856 KB
testcase_15 WA -
testcase_16 AC 9 ms
5,632 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 14 ms
11,008 KB
testcase_20 WA -
testcase_21 AC 18 ms
8,704 KB
testcase_22 AC 28 ms
12,736 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 51 ms
15,060 KB
testcase_26 AC 51 ms
15,080 KB
testcase_27 AC 54 ms
15,016 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.back(); 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