#if loc||local #define _GLIBCXX_DEBUG #endif #include using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = int_fast64_t; using pll = pair; constexpr ll INF = 1LL<<60; constexpr ll MOD = 1e9+7; template bool chmax(T &a,const T &b){if(a bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} #if loc||local templatevoid dump(T&& t){cerr< void dump(T&& h, Ts&&... t){cerr<(t)...);} #else void dump(){} template void dump(T&& h, Ts&&... t){} #endif template istream &operator>>(istream&is,vector&v){for(auto &elemnt:v)is>>elemnt;return is;} template istream &operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} template ostream &operator<<(ostream& os,vectorconst& v){for(auto const& vi:v)os< ostream &operator<<(ostream& os,pairconst& p){os<vector vec(size_t a){return vector(a);} templateauto vec(size_t a, Ts... ts){return vector(ts...))>(a, vec(ts...));} using vertex = struct vertex{ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}}; using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}}; using weighted_adjlist = vector>; using weighted_edge = vector; auto Dijkstra(weighted_adjlist& adj,ll S){ ll N=(ll)adj.size(); vector dist(N,(1LL<<60)); vector prev_v(N,-1LL); using pll = pair; priority_queue,greater<>> que; dist[S]=0LL; que.emplace(dist[S],S); while(!que.empty()){ ll cost,from; tie(cost,from) = que.top(); que.pop(); if(dist[from]>n>>m>>p; ll s,g; cin>>s>>g; weighted_adjlist adj(n+1); rep(i,m){ int u,v; cin>>u>>v; adj[u].emplace_back(v,1); adj[v].emplace_back(u,1); } auto dist_s = Dijkstra(adj,s); auto dist_g = Dijkstra(adj,g); // 1 indexed set ans; for(int v=1;v<=n;++v){ ll min_dist = dist_s[v]+dist_g[v]; if(min_dist>p)continue; if((p-min_dist)%2==0){ ans.emplace(v); continue; } for(auto&nv:adj[v]){ if(dist_s[v]==dist_s[nv.to] and dist_s[v]+dist_s[nv.to]+1<=p ){ ans.emplace(v); break; } if(dist_g[v]==dist_g[nv.to] and dist_g[v]+dist_g[nv.to]+1<=p){ ans.emplace(v); break; } } } if(size(ans)==0){ cout<< -1 <