Need Help Debugging a Solution for Cooperative game Game on Codeforces (TLE on Test Case 80)

Revision en1, by pranjalkhatri950, 2024-12-05 17:36:47

Hi codeforces :)

I hope you're doing well! I'm currently working on a problem from Codeforces, and I'm facing some issues with my solution.

Problem Statement can be found here I was doing USACO silver when i encountered it.

My solution simply implements Floyd's cycle detection, where i use 0,1 as slow and fast pointer respectively and when the meet i use the remaining people (2,3,4,5,6,7,8,9) as the slow pointer and (0,1) as fast pointer. This should have queries less than 3(t+c) (I have calculated that). However this produces TLE on test case 80 (however the error shows query limit exceeded). When i compare it with the USACO solution it produces same output which runs fine.

MY solution

USACO solution , submission

I’m hoping someone from the Codeforces community can provide insights or suggestions on how to optimize this solution. Any advice on handling time complexity or debugging the interaction would be really helpful. Thank you in advance!

Looking forward to your suggestions!

Best regards, PK

Tags c++, graphs, cycle detection, help me

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English pranjalkhatri950 2024-12-05 17:36:47 1437 Initial revision (published)