#include #include #include using namespace std; const int maxn = 1e5 + 5; int n, m; vector graph[maxn]; vector bfs(int S, int E) { queue q; q.push(S); q.push(0); vector visited(n + 1, false); visited[S] = true; vector path(n, -1); while(!q.empty()) { int node = q.front(); q.pop(); int dist = q.front(); q.pop(); for(int neighbour : graph[node]) { if(!visited[neighbour]) { visited[neighbour] = true; q.push(neighbour); q.push(dist + 1); path[neighbour] = node; } } } return path; } int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } int S, E; cin >> S >> E; vector p = bfs(S, E); while(E != S) { cout << E << " "; E = p[E]; } cout << S << endl; return 0; }