Randomized solution in Div2 E

Revision en4, by _shanky, 2020-03-15 10:32:14

In yesterday's Div2 E I was stuck at finding the shortest cycle. I was using dfs and each time a backedge (x,y) occurred I was keeping the minimum of level[x]-level[y]+1 only to realize it was wrong. The answer would depend on the order of dfs traversal. So I randomly shuffled adjacency lists few times and used dfs each time while keeping the minimum. I managed to pass all test cases. Is there any proof that the correct answer will be found with high probability with this approach or I just managed to be lucky?

Link to the submission

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English _shanky 2020-03-15 10:32:14 0 (published)
en3 English _shanky 2020-03-15 10:31:31 8 Tiny change: 'each time and keeping t' -> 'each time while keeping t'
en2 English _shanky 2020-03-15 10:30:14 60
en1 English _shanky 2020-03-15 10:28:26 570 Initial revision (saved to drafts)