← CSES Better

Minimizing Edges

USACO · 2021 · February · platinum-2

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

greedy · graph-algorithms

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

sample trace

Minimizing Edges: greedy walkthrough

Minimizing Edges: use the linked editorial?s greedy, graph algorithms idea on the published sample, then verify the displayed output.

Published input2 5 5 1 2 2 3 2 5 1 4 4 5 5 5 1 2 2 3 3 4 4 5 1 5 7 8 10 1 2 1 3 1 4 1 5 2 6 3 7 4 8 5 8 6 7 8 8 10 11 1 2 1 5 1 6 2 3 3 4 4 5 4 10 6 7 7 8 8 9 9 9 13 15 1 2 1 5 1 6 2 3 3 4 4 5 6 7 7 8 7 11 8 9 9 10 10 11 11 12 11 13 12 13 16 18 1 2 1 7 1 8 2 3 3 4 4 5 5 6 6 7 8 9 9 10 9 15 9 16 10 11 11 12 12 13 13 14 14 15 14 16 21 22 1 2 1 9 1 12 2 3 3 4 4 5 5 6 6 7 7 8 7 11 8 9 8 10 12 13 13 14 13 21 14 15 15 16 16 17 17 18 18 19 19 20 20 21 20 26 1 2 1 5 1 6 2 3 3 4 4 5 4 7 6 8 8 9 8 11 8 12 8 13 8 14 8 15 8 16 8 17 9 10 10 18 11 18 12 19 13 20 14 20 15 20 16 20 17 20 19 20 24 31 1 2 1 7 1 8 2 3 3 4 4 5 5 6 6 7 6 9 8 10 10 11 10 16 10 17 10 18 10 19 10 20 11 12 12 13 13 14 14 15 15 16 15 17 15 18 15 19 15 20 15 21 15 22 15 23 15 24 21 22 23 24modelAlgorithm ideaProcess choices in the order justified by the editorial and maintain the invariant that each accepted choice remains safe.task resultExpected output4 5 10 11 15 18 22 26 31
  1. 1

    Order

    Arrange candidates by the criterion used by the task?s greedy strategy.
  2. 2

    Choose

    Accept the next locally safe option while preserving the feasibility invariant.
  3. 3

    Finish

    Read the accumulated result and check it against the sample output.
  4. 4

    Verify the sample

    Use the published sample output to check the result of this idea on the displayed input.
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.