結果
問題 | No.1190 Points |
ユーザー |
![]() |
提出日時 | 2021-02-11 09:58:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 1,560 bytes |
コンパイル時間 | 2,360 ms |
コンパイル使用メモリ | 207,580 KB |
最終ジャッジ日時 | 2025-01-18 17:19:47 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d %d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) begin(v),end(v)template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }using ll = long long;using pii = pair<int, int>;constexpr ll INF = 1ll<<30;constexpr ll longINF = 1ll<<60;constexpr ll MOD = 1000000007;constexpr bool debug = false;//---------------------------------//int main() {int N, M, P, S, G;cin >> N >> M >> P >> S >> G;--S; --G;vector<vector<int>> g(N);REP(i, M) {int u, v;scanf("%d %d", &u, &v);--u; --v;g[u].emplace_back(v);g[v].emplace_back(u);}auto solve = [&](int s) {vector dist(N, vector(2, INF)); // [i][j] := j=0(even), j=1(odd)queue<pii> que; // u, dque.emplace(s, 0);dist[s][0] = 0;while (!que.empty()) {auto [u, d] = que.front();que.pop();for (int v : g[u]) if (chmin(dist[v][(d + 1) & 1], d + 1)) que.emplace(v, d + 1);}return dist;};auto d1 = solve(S), d2 = solve(G);vector<int> ans;REP(i, N) {bool ok = false;REP(j, 2) REP(k, 2) {if (d1[i][j] == INF || d2[i][k] == INF) continue;const int d = d1[i][j] + d2[i][k];ok |= d <= P && (P - d) % 2 == 0;}if (ok) ans.emplace_back(i);}if (ans.empty()) puts("-1");else {cout << ans.size() << endl;for (int i : ans) printf("%d\n", i + 1);}}