Graph Theory37 sections · 1633 units
Open in Course

CSES 1673 High Score - The Reachability Trap

(Not all cycles matter)

A negative cycle only gives infinite score if it is on some path connecting node 11 to node N. If the cycle is unreachable or does not lead to N, it does not help. You need to check two things:

1.1. Is there a negative cycle?

2.2. Is it reachable starting at 11 AND can it reach N? Both conditions must hold for the answer to be 1-1. Check reachability using BFS on the original and reversed graphs.