← CSES Better

Department Strengths

INOI · 2020 · Indian National Olympiad in Informatics · INOI2001

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

trees · department-parity · levels

The organizer’s problem statement is available at the official source link.

department tree

Department parity constrains the head ID

Each connected tree is a department. Even-sized departments require the head to have the smallest ID; odd-sized departments require the largest. Team strength is the sum of employee levels.

State table
Department sizeHead ID ruleTeam strength
evenminimum IDsum of employee levels
oddmaximum IDsum of employee levels
  1. 1

    Find each department head

    A department is a tree; its size parity determines whether its head has the minimum or maximum employee ID.
  2. 2

    Assign employee levels

    The head is level 1; each employee is one level below their manager.
  3. 3

    Sum by department type

    Add levels separately for employees in even-sized and odd-sized departments.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.