結果

問題 No.1190 Points
ユーザー minatominato
提出日時 2020-08-27 09:58:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 2,570 bytes
コンパイル時間 3,170 ms
コンパイル使用メモリ 252,736 KB
実行使用メモリ 16,300 KB
最終ジャッジ日時 2024-04-27 03:27:08
合計ジャッジ時間 5,591 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 41 ms
12,740 KB
testcase_04 AC 36 ms
11,392 KB
testcase_05 AC 35 ms
10,880 KB
testcase_06 AC 51 ms
14,908 KB
testcase_07 AC 60 ms
15,908 KB
testcase_08 AC 58 ms
16,220 KB
testcase_09 AC 59 ms
14,796 KB
testcase_10 AC 61 ms
16,300 KB
testcase_11 AC 43 ms
11,776 KB
testcase_12 AC 59 ms
15,776 KB
testcase_13 AC 39 ms
10,220 KB
testcase_14 AC 15 ms
9,188 KB
testcase_15 AC 64 ms
15,208 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 63 ms
14,756 KB
testcase_18 AC 35 ms
7,552 KB
testcase_19 AC 12 ms
10,108 KB
testcase_20 AC 43 ms
9,216 KB
testcase_21 AC 20 ms
8,220 KB
testcase_22 AC 26 ms
11,932 KB
testcase_23 AC 72 ms
15,572 KB
testcase_24 AC 67 ms
15,636 KB
testcase_25 AC 47 ms
14,100 KB
testcase_26 AC 45 ms
14,212 KB
testcase_27 AC 43 ms
14,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() {cout << "\n";}
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<int> bfs(const vector<vector<int>> &G, int s) {
    vector<int> ret(G.size(),MOD);
    ret[s] = 0;
    queue<int> que;
    que.emplace(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (ret[nv] != MOD) continue;
            ret[nv] = ret[v] + 1;
            que.emplace(nv);
        }
    }

    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);   
    int N,M,P; cin >> N >> M >> P;
    int s,g; cin >> s >> g;
    --s; --g;
    vector<vector<int>> G(N*2);
    rep(i,M) {
        int u,v; cin >> u >> v;
        --u; --v;
        G[u].emplace_back(v+N);
        G[v+N].emplace_back(u);
        G[v].emplace_back(u+N);
        G[u+N].emplace_back(v);
    }

    auto dist_s = bfs(G,s);
    if (P&1) g += N;
    if (dist_s[g] > P) {
        cout << -1 << ln;
        return 0;
    }

    auto dist_g = bfs(G,g);
    vector<int> ans;
    rep(i,N) {
        if (dist_s[i]+dist_g[i]<=P or dist_s[i+N]+dist_g[i+N]<=P) ans.emplace_back(i+1);
    }

    cout << ans.size() << ln;
    for (auto i : ans) cout << i << ln;
}
0