結果
問題 |
No.1190 Points
|
ユーザー |
![]() |
提出日時 | 2020-08-22 14:00:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 1,433 bytes |
コンパイル時間 | 2,556 ms |
コンパイル使用メモリ | 204,268 KB |
最終ジャッジ日時 | 2025-01-13 08:19:45 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <class T> using vvvec = vector<vvec<T>>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M,P; cin >> N >> M >> P; int S,T; cin >> S >> T; S--; T--; vvec<int> g(N); for(int i=0;i<M;i++){ int a,b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } int inf = 1e9+5; vvec<int> distS(N,vec<int>(2,inf)),distT(N,vec<int>(2,inf)); auto bfs = [&](int s,vvec<int>& dist)->void{ queue<pair<int,int>> Q; dist[s][0] = 0; Q.push({s,0}); while(!Q.empty()){ auto [cur,p] = Q.front(); Q.pop(); for(auto& to:g[cur]){ if(dist[to][p^1]==inf){ dist[to][p^1] = dist[cur][p]+1; Q.push({to,p^1}); } } } }; bfs(S,distS); bfs(T,distT); vec<int> ans; for(int i=0;i<N;i++) for(int a=0;a<2;a++) for(int b=0;b<2;b++) if((a+b)%2==P%2){ if(distS[i][a]+distT[i][b]<=P) ans.push_back(i); } if(ans.empty()){ cout << -1 << "\n"; return 0; } ans.erase(unique(ans.begin(),ans.end()),ans.end()); cout << ans.size() << "\n"; for(auto& x:ans) cout << x+1 << "\n"; }