#include #include #include using namespace std; const int maxn = 100005; vector graph[maxn]; int main() { ios_base::sync_with_stdio(false); int num_of_vertices; cin >> num_of_vertices; int num_of_edges; cin >> num_of_edges; for(int i = 0; i < num_of_edges; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } int S, E; cin >> S >> E; queue q; q.push(S); q.push(0); vector visited(num_of_vertices, false); while(!q.empty()) { int c_node = q.front(); q.pop(); int dist = q.front(); q.pop(); if(c_node == E) { cout << dist << endl; break; } for(int i = 0; i < graph[c_node].size(); i++) { int neighbour = graph[c_node][i]; if(!visited[neighbour]) { q.push(neighbour); q.push(dist + 1); visited[neighbour] = true; } } } return 0; }