#include #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif template bool chmin(T &a, const U &b){ return (a > b ? a = b, true : false); } template bool chmax(T &a, const U &b){ return (a < b ? a = b, true : false); } template void fill_array(T (&a)[N], const U &v){ std::fill((U*)a, (U*)(a + N), v); } template auto make_vector(int n, int m, const T &value){ return std::vector>(n, std::vector(m, value)); } template std::ostream& operator<<(std::ostream &s, const std::vector &a){ for(auto it = a.begin(); it != a.end(); ++it){ if(it != a.begin()) s << " "; s << *it; } return s; } template std::istream& operator>>(std::istream &s, std::vector &a){ for(auto &x : a) s >> x; return s; } /** * @title Graph template * @docs graph_template.md */ template class Edge{ public: int from,to; Cost cost; Edge() {} Edge(int to, Cost cost): to(to), cost(cost){} Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){} }; template using Graph = std::vector>>; template using Tree = std::vector>>; template void add_edge(C &g, int from, int to, T w = 1){ g[from].emplace_back(from, to, w); } template void add_undirected(C &g, int a, int b, T w = 1){ add_edge(g, a, b, w); add_edge(g, b, a, w); } /** * @title BFS shortest path * @docs bfs_shortest_path.md */ template std::vector> bfs_shortest_path(const Graph &g, const std::vector &src){ const int n = g.size(); std::vector> ret(n, std::nullopt); std::vector visited(n); std::queue q; for(auto s : src){ ret[s] = 0; q.push(s); } while(not q.empty()){ const int cur = q.front(); q.pop(); if(visited[cur]) continue; visited[cur] = true; for(auto &e : g[cur]){ if(not ret[e.to] or *ret[e.to] > *ret[e.from] + 1){ ret[e.to] = *ret[e.from] + 1; q.push(e.to); } } } return ret; } namespace solver{ constexpr int INF = INT_MAX; void init(){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); std::cerr << std::fixed << std::setprecision(12); std::cin.exceptions(std::ios_base::failbit); } void solve(){ int N, M, P; std::cin >> N >> M >> P; int S, G; std::cin >> S >> G; --S, --G; Graph g(2 * N); for(int i = 0; i < M; ++i){ int u, v; std::cin >> u >> v; --u, --v; add_undirected(g, u, v + N, 1); add_undirected(g, u + N, v, 1); } auto s_dist = bfs_shortest_path(g, {S}); auto g_dist = bfs_shortest_path(g, {G}); std::vector ans; for(int i = 0; i < N; ++i){ bool ok = false; if(P % 2 == 0){ if(s_dist[i].value_or(INF) + g_dist[i].value_or(INF) <= P or s_dist[i + N].value_or(INF) + g_dist[i + N].value_or(INF) <= P){ ok = true; } }else{ if(s_dist[i].value_or(INF) + g_dist[i + N].value_or(INF) <= P or s_dist[i + N].value_or(INF) + g_dist[i].value_or(INF) <= P){ ok = true; } } if(ok) ans.push_back(i + 1); } if(ans.empty()) std::cout << -1 << "\n"; else{ std::cout << ans.size() << "\n"; for(auto x : ans) std::cout << x << "\n"; } } } int main(){ solver::init(); while(true){ try{ solver::solve(); }catch(const std::istream::failure &e){ break; } } return 0; }