結果
| 問題 |
No.1190 Points
|
| ユーザー |
|
| 提出日時 | 2020-08-31 04:42:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 2,000 ms |
| コード長 | 2,142 bytes |
| コンパイル時間 | 1,890 ms |
| コンパイル使用メモリ | 174,876 KB |
| 実行使用メモリ | 11,420 KB |
| 最終ジャッジ日時 | 2024-11-15 16:21:48 |
| 合計ジャッジ時間 | 5,871 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
const int INF = 1001001001;
const int MAX_N = 112345;
int fromS[MAX_N][2];
int fromG[MAX_N][2];
int N;
vector<int> g[MAX_N];
void search(int s, int dist[MAX_N][2]) {
REP(i, MAX_N) REP(j, 2) dist[i][j] = INF;
queue<pair<int,int>> q;
q.push({s, 0});
dist[s][0] = 0;
while (!q.empty()) {
auto p = q.front(); q.pop();
int u = p.first;
int f = p.second;
for (int v : g[u]) {
if (dist[v][1-f] > dist[u][f] + 1) {
dist[v][1-f] = dist[u][f] + 1;
q.push({v, 1-f});
}
}
}
}
int main2() {
REP(i, MAX_N) g[i].clear();
N = nextLong();
int M = nextLong();
int P = nextLong();
int S = nextLong() - 1;
int G = nextLong() - 1;
REP(i, M) {
int a = nextLong() - 1;
int b = nextLong() - 1;
g[a].push_back(b);
g[b].push_back(a);
}
search(S, fromS);
search(G, fromG);
// REP(i, N) { cout << fromS[i][0] << " "; } cout << endl;
// REP(i, N) { cout << fromS[i][1] << " "; } cout << endl;
// REP(i, N) { cout << fromG[i][0] << " "; } cout << endl;
// REP(i, N) { cout << fromG[i][1] << " "; } cout << endl;
if (fromS[G][P%2] == INF) {
cout << -1 << endl;
return 0;
}
vector<int> ans;
REP(i, N) {
bool ok = false;
REP(f1, 2) REP(f2, 2) {
int pp = fromS[i][f1] + fromG[i][f2];
if (pp <= P && (P - pp) % 2 == 0) ok = true;
}
if (ok) ans.push_back(i+1);
}
cout << ans.size() << endl;
REP(i, ans.size())
cout << ans[i] << '\n';
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
}