// to find the distance of each node from root(single source sorthest path (on tress))
vector g[100001];
vector visi(100001, 0);
vector distance(100001);
void dfs(ll v,ll dist){
visi[v] = 1;
distance[v] = dist;
for(ll child: g[v])
{
if(visi[child]==0)
dfs(child,dist+1);
}
}
//the final dist array will give the shortest distance from 'v' node.
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter