Graph Girth solution is wrong

The optimal solution described here got WA in cses. https://usaco.guide/solutions/cses-1707?lang=cpp

The early return (GOTO) misses some shorter cycles. for graphs such as:

6 7
1 2
2 3
3 4
4 1
1 6
1 5
5 6

We can modify the algorithm above to return either the length of the shortest cycle or the length of the shortest cycle plus one in \mathcal{O}(N^2) time.

It’s not a solution to the CSES problem.

1 Like