#include #include #include template struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template struct Graph { std::vector>> graph; Graph(int n = 0) : graph(n) {} void span(bool direct, int src, int dst, Cost cost = 1) { graph[src].emplace_back(src, dst, cost); if (!direct) graph[dst].emplace_back(dst, src, cost); } int size() const { return graph.size(); } void clear() { graph.clear(); } void resize(int n) { graph.resize(n); } std::vector>& operator[](int v) { return graph[v]; } std::vector> operator[](int v) const { return graph[v]; } }; template std::vector bfs(const Graph& graph, int s) { std::vector dist(graph.size(), -1); dist[s] = 0; std::queue que; que.push(s); while (!que.empty()) { int v = que.front(); que.pop(); for (const auto& e : graph[v]) { if (dist[e.dst] != -1) continue; dist[e.dst] = dist[v] + e.cost; que.push(e.dst); } } return dist; } void solve() { int n, m, k, s, g; std::cin >> n >> m >> k >> s >> g; --s, --g; Graph<> graph(n * 2); auto enc = [&](int v, int t) { return v + t * n; }; while (m--) { int u, v; std::cin >> u >> v; --u, --v; for (int t = 0; t < 2; ++t) { graph.span(false, enc(u, t), enc(v, 1 - t)); } } auto sdist = bfs(graph, enc(s, 0)); auto gdist = bfs(graph, enc(g, 0)); std::vector ans; for (int v = 0; v < n; ++v) { for (int t = 0; t < 2; ++t) { int nt = (t + k) % 2; if (sdist[enc(v, t)] != -1 && gdist[enc(v, nt)] != -1 && sdist[enc(v, t)] + gdist[enc(v, nt)] <= k) { ans.push_back(v); break; } } } if (ans.empty()) { std::cout << "-1\n"; return; } std::cout << ans.size() << "\n"; for (auto v : ans) std::cout << v + 1 << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }