Graph Theory37 sections · 1633 units
Open in Course

CSES 1673 High Score - The Maximum-Score Trick

(Negate and minimize)

Maximum score equals the minimum of negated scores. Negate all edge weights and run shortest-path algorithms.

This converts the problem into finding the shortest path with negated weights. If a negative cycle exists and affects the path, the answer is 1-1 (infinite score).

Use Bellman-Ford to detect negative cycles after negation. Run N1N-1 relaxation rounds, then check if a NN-th round still relaxes any edge reachable from 11 that can reach NN. If so, output 1-1.