← CSES Better

Trees

INOI · 2024 · Indian National Olympiad in Informatics · Problem 3

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 · path-queries · counting

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

tree pair comparison

Compare the maximum edge on two unique paths

For each unordered pair p < q, compare the maximum edge weight on its unique path in tree X with the corresponding maximum in tree Y. Count pairs satisfying costX(p,q) <= costY(p,q).

State table
Tree X pathTree Y pathPair test
max edge X(p,q)max edge Y(p,q)compare as stated
  1. 1

    Choose node pair

    Choose one unordered node pair.
  2. 2

    Compare path maxima

    Find the maximum edge weight on its unique path in each weighted tree.
  3. 3

    Count matching pairs

    Count the pair when its two path maxima satisfy the official comparison relation.
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.