Graph Theory37 sections · 1633 units
Open in Course

CSES 1673 High Score - Walkthrough

(Trace execution)

Graph: 121 \to 2 (score 33), 232 \to 3 (score 44), 323 \to 2 (score 55), 242 \to 4 (score 11), n=4n = 4. After negating: 121 \to 2 (3-3), 232 \to 3 (4-4), 323 \to 2 (5-5), 242 \to 4 (1-1). Run Bellman-Ford: after 33 iterations, dist[2] = -12, dist[3] = -7, dist[4] = -4.

The 44-th iteration improves dist[3] (to 16-16) and dist[4] (to 13-13) due to cycle 232 \leftrightarrow 3. Mark all nodes that improved and all nodes reachable from them.

Check two-way reachability: node 22 (the cycle) is reachable from node 11 (direct edge 121 \to 2). Node 44 is reachable from node 22 (direct edge 242 \to 4). Both checks pass. Output 1-1.