Mon Jan 10 2022 06:57:07 GMT+0000 (Coordinated Universal Time)
Saved by @vaibhav_55
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
Copy this HTML code:
Preview:
open_in_newInstructions on embedding in Medium
Comments