#include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define endl "\n" void solved(){ int n; cin>>n; //vector a(n+1); vector> e[n+1]; for(int i=1;i<=n-1;i++){ int a; cin>>a; e[i].push_back({a,1}); } for(int i=2;i<=n-1;i++) e[i].push_back({i-1,0}); vector dist(n+1,2e6); dist[1]=0; deque q; q.push_back(1); while(q.size()){ auto u=q.front(); //cout<