#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main(){
// freopen("t.txt", "r", stdin);
int nodes, edges;
cin >> nodes >> edges;
vector<vector<int>> graph(nodes + 1);
vector<int> distance(nodes + 1, -1);
vector<int> parent(nodes + 1);
vector<int> shortestPath;
queue<int> bfs;
while(edges--){
int from, to;
cin >> from >> to;
graph[from].push_back(to);
graph[to].push_back(from);
}
int src = 1;
bfs.push(src);
distance[src] = 0;
parent[src] = src;
while(!bfs.empty()){
int node = bfs.front();
bfs.pop();
for(int child : graph[node]){
if(distance[child] == -1){
bfs.push(child);
distance[child] = distance[node]+1;
parent[child] = node;
}
}
}
cout << '\n';
for(int node = 1; node <= nodes; node++)
cout << node <<" -> "<< distance[node] <<" Parent : "<< parent[node] <<'\n';
int dist = 7;
cout <<"\nThe Shortest Path from "<< src <<" to "<< dist <<" is : ";
shortestPath.push_back(dist);
do{
dist = parent[dist];
shortestPath.push_back(dist);
}while(dist != src);
reverse(shortestPath.begin(), shortestPath.end());
for(int node : shortestPath)
cout << node <<' ';
cout <<"\nand The distance of Path is : "<< distance[shortestPath[shortestPath.size()-1]] <<'\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+CgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCl7CgogIC8vICBmcmVvcGVuKCJ0LnR4dCIsICJyIiwgc3RkaW4pOwoKICAgIGludCBub2RlcywgZWRnZXM7CiAgICBjaW4gPj4gbm9kZXMgPj4gZWRnZXM7CgogICAgdmVjdG9yPHZlY3RvcjxpbnQ+PiBncmFwaChub2RlcyArIDEpOwoKICAgIHZlY3RvcjxpbnQ+IGRpc3RhbmNlKG5vZGVzICsgMSwgLTEpOwogICAgdmVjdG9yPGludD4gcGFyZW50KG5vZGVzICsgMSk7CiAgICB2ZWN0b3I8aW50PiBzaG9ydGVzdFBhdGg7CgogICAgcXVldWU8aW50PiBiZnM7CgogICAgd2hpbGUoZWRnZXMtLSl7CiAgICAgICBpbnQgZnJvbSwgdG87CiAgICAgICBjaW4gPj4gZnJvbSA+PiB0bzsKCiAgICAgICBncmFwaFtmcm9tXS5wdXNoX2JhY2sodG8pOwogICAgICAgZ3JhcGhbdG9dLnB1c2hfYmFjayhmcm9tKTsKICAgIH0KCiAgICBpbnQgc3JjID0gMTsKICAgIGJmcy5wdXNoKHNyYyk7CiAgICBkaXN0YW5jZVtzcmNdID0gMDsKICAgIHBhcmVudFtzcmNdID0gc3JjOwoKCiAgICB3aGlsZSghYmZzLmVtcHR5KCkpewogICAgICAgIGludCBub2RlID0gYmZzLmZyb250KCk7CiAgICAgICAgYmZzLnBvcCgpOwoKICAgICAgICBmb3IoaW50IGNoaWxkIDogZ3JhcGhbbm9kZV0pewogICAgICAgICAgICBpZihkaXN0YW5jZVtjaGlsZF0gPT0gLTEpewogICAgICAgICAgICAgICAgYmZzLnB1c2goY2hpbGQpOwoKICAgICAgICAgICAgICAgIGRpc3RhbmNlW2NoaWxkXSA9IGRpc3RhbmNlW25vZGVdKzE7CiAgICAgICAgICAgICAgICBwYXJlbnRbY2hpbGRdID0gbm9kZTsKICAgICAgICAgICAgfQogICAgICAgIH0KCgogICAgfQogICAgY291dCA8PCAnXG4nOwogICAgZm9yKGludCBub2RlID0gMTsgbm9kZSA8PSBub2Rlczsgbm9kZSsrKQogICAgICAgIGNvdXQgPDwgbm9kZSA8PCIgLT4gIjw8IGRpc3RhbmNlW25vZGVdIDw8IiBQYXJlbnQgOiAiPDwgcGFyZW50W25vZGVdIDw8J1xuJzsKCgogICAgaW50IGRpc3QgPSA3OwoKICAgIGNvdXQgPDwiXG5UaGUgU2hvcnRlc3QgUGF0aCBmcm9tICI8PCBzcmMgPDwiIHRvICI8PCBkaXN0IDw8IiBpcyA6ICI7CgogICAgc2hvcnRlc3RQYXRoLnB1c2hfYmFjayhkaXN0KTsKICAgIGRvewogIC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