← CSES Better

Counting Graphs

USACO · 2021 · February · platinum-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

graph-algorithms

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

sample trace

Counting Graphs: graph algorithms walkthrough

Counting Graphs: use the linked editorial?s graph algorithms idea on the published sample, then verify the displayed output.

Published input1 5 4 1 2 2 3 1 4 3 5 7 4 6 1 2 2 3 3 4 1 3 2 4 1 4 5 5 1 2 2 3 3 4 4 5 1 5 5 7 1 2 1 3 1 5 2 4 3 3 3 4 4 5 6 6 1 2 2 3 3 4 4 5 5 6 6 6 6 7 1 2 2 3 1 3 1 4 4 5 5 6 1 6 10 10 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 22 28 1 2 2 3 3 4 4 5 5 6 6 7 1 7 1 8 3 9 8 10 10 11 10 12 10 13 10 14 11 15 12 16 13 17 14 18 9 15 9 16 9 17 9 18 15 19 19 20 15 20 16 21 21 22 16 22modelAlgorithm ideaRepresent the task?s objects and connections as a graph, then use the editorial?s traversal or path method to obtain the requested property.task resultExpected output3 45 35 11 1 15 371842544 256838540
  1. 1

    Model

    Make one vertex per task object and add an edge for each permitted relationship.
  2. 2

    Process

    Traverse or relax the graph according to the task?s path or reachability rule.
  3. 3

    Read

    Use the reached set or path result to produce the requested 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.