vector g[10001];
vetor visi(10001,0);
vector subtree(10001, 0);
ll dfs(ll v) {
visi[v] = 1;
ll curr = 1;
for (ll child : g[v]) {
if (visi[child] == 0)
curr += dfs(child);
}
subtree[v] = curr;
return curr;
}
//here,subtree array will give the size of each node's subtree
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