getting TLE in GSS1



Why am I getting TLE in this code?

my code :

problem :

I saw some solutions while googling and I don’t think they are using lazy updates. What can I do?

p.s. I modified the code which I think makes code a bit faster. But still I am getting a TLE verdict.

code :