#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template using pqueue = priority_queue, greater>; int main() { constexpr int inf = INT_MAX / 4; int n, m, p; cin >> n >> m >> p; int start, goal; cin >> start >> goal; --start; --goal; auto g = vec(uns, n, 0); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u; --v; g[u].push_back(v); g[v].push_back(u); } auto bfs = [&](int s) { auto dist = vec(-1, n); queue que; dist[s] = 0; que.push(s); while (!que.empty()) { int c = que.front(); que.pop(); for (auto v : g[c]) { if (0 <= dist[v]) continue; dist[v] = dist[c] + 1; que.push(v); } } return dist; }; auto dist1_s = bfs(start); auto dist1_g = bfs(goal); auto start_s = vec>(uns, 0); auto start_g = vec>(uns, 0); for (int u = 0; u < n; ++u) { for (auto v : g[u]) { if (dist1_s[u] == dist1_s[v]) { start_s.emplace_back(dist1_s[v] + 1, u); start_s.emplace_back(dist1_s[v] + 1, v); } if (dist1_g[u] == dist1_g[v]) { start_g.emplace_back(dist1_g[v] + 1, u); start_g.emplace_back(dist1_g[v] + 1, v); } } } if (size(start_s) == 0 && size(start_g) == 0) { auto ans = vec(uns, 0); for (int i = 0; i < n; ++i) { auto d = dist1_s[i] + dist1_g[i]; if (d <= p && d % 2 == p % 2) { ans.push_back(i + 1); } } if (size(ans) != 0) { cout << size(ans) << endl; for (auto e : ans) { cout << e << endl; } } else { cout << -1 << endl; } return 0; } auto dijkstra = [&](auto &&vtxs) { auto dist = vec(inf, n); pqueue> que; for (auto [c, v] : vtxs) { dist[v] = min(dist[v], c); que.push({ c, v }); } while (!que.empty()) { auto [_, u] = que.top(); que.pop(); for (auto v : g[u]) { if (dist[v] <= dist[u] + 1) continue; dist[v] = dist[u] + 1; que.push({ dist[v], v }); } } return dist; }; auto dist2_s = dijkstra(start_s); auto dist2_g = dijkstra(start_g); auto ans = vec(uns, 0); for (int i = 0; i < n; ++i) { auto d1 = dist1_s[i]; auto d2 = dist2_s[i]; auto d3 = dist1_g[i]; auto d4 = dist2_g[i]; if (d1 < 0 || d3 < 0) continue; if (d1 % 2 == 1) { swap(d1, d2); } if (d3 % 2 == 1) { swap(d3, d4); } if (p % 2 == 0) { if (d1 + d3 <= p || d2 + d4 <= p) { ans.push_back(i + 1); } } else { if (d1 + d4 <= p || d2 + d3 <= p) { ans.push_back(i + 1); } } } if (size(ans) != 0) { cout << size(ans) << endl; for (auto e : ans) { cout << e << endl; } } else { cout << -1 << endl; } }