Graph Theory37 sections · 1633 units
Open in Course

CSES 1674 Subordinates - Strategy

Team size calculation with DFS

If I am a manager, the size of my team is: 11 (Myself) ++ The total team size of all my direct reports. For a leaf employee (no direct reports), the team size is 11 (themselves). The boss's team includes the entire company.

This is classic tree DP. You compute the subtree size for each node by summing the subtree sizes of its children and adding 11. Then, the number of subordinates is subtree_size - 11. The leaf employees have 00 subordinates.