/** * author: otera **/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60 ; const ll mod=1e9+7 ; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair P; typedef pair LDP; typedef pair LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int n, m, p; vector> g; int s, t; void solve() { cin >> n >> m >> p; g.assign(n, vector()); cin >> s >> t; -- s, -- t; rep(i, m) { int u, v; cin >> u >> v; -- u, -- v; g[u].pb(v); g[v].pb(u); } vector e_d(n, inf), o_d(n, inf); vector e_prev(n, -1), o_prev(n, -1); e_d[s] = 0; queue que; que.push(s); while(!que.empty()) { int v = que.front(); que.pop(); for(int nv: g[v]) { if(chmin(e_d[nv], o_d[v] + 1)) { que.push(nv); e_prev[nv] = v; } if(chmin(o_d[nv], e_d[v] + 1)) { que.push(nv); o_prev[nv] = v; } } } if(p % 2 == 0) { if(p < e_d[t]) cout << -1 << endl; else { vector ans; ans.pb(t); int prev = e_prev[t]; bool pr = 0; while(prev != -1) { ans.pb(prev); if(!pr) prev = o_prev[prev]; else prev = e_prev[prev]; pr ^= 1; } sort(all(ans)); cout << (int)ans.size() << endl; for(int x: ans) cout << x + 1 << endl; } } else { if(p < o_d[t]) cout << -1 << endl; else { vector ans; ans.pb(t); int prev = o_prev[t]; bool pr = 0; while(prev != -1) { ans.pb(prev); if(!pr) prev = e_prev[prev]; else prev = o_prev[prev]; pr ^= 1; } sort(all(ans)); cout << (int)ans.size() << endl; for(int x: ans) cout << x + 1 << endl; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }