Graph Theory37 sections · 1633 units
Open in Course

CSES 1674 Subordinates - Problem Statement

Count employees under each manager

Problem: Subordinates (CSES) Task: You have a company with nn employees. Each employee except the boss has one direct manager. For each employee, count how many subordinates they have (including indirect subordinates).

This is a subtree size problem. If you root the tree at the boss, the number of subordinates of a node is the size of its subtree minus 11 (itself). Compute subtree sizes with a single DFS traversal: the size of a node equals 11 plus the sum of sizes of all its children.