Code failing test cases in BUGLIFE

I was solving BUGLIFE.

My code :

Why is this not passing the test cases? Can someone please tell where I made an error in my code?

1 Like

Someone please help @vijju123 @ssjgz

Fill vis and col with 0s.
memset(vis, 0, sizeof(vis));
memset(col, 0, sizeof(col));

1 Like

And why are you clearing only the ith adjacency list?

Oh yeah I forgot that

1 Like

I forgot to add a loop actually, thanks a lot :smiley:

1 Like

And still my code doesn’t work :frowning:

Why are you running dfs before you’ve even finished reading in the edges?


Also, review the Output format carefully.


Yet another example of where the simple act of having your Editor indent your code would make a bug immediately obvious - why won’t people do this??? XD


How many adjaceny lists are there? How many are you clearing?

Also, your variable names are terrible. It is hard for us to debug.

Debugged, new code :
Passes test cases, but gives WA. Where am I going wrong?


Going to go ahead and mention that the whole “global adjacency lists are a terrible, error-prone idea” yet again, but people seem to be bewilderingly keen on using them, so :man_shrugging:


Got AC. Thanks @ssjgz @therealnishuz
My code : (Just in case anyone wants)

1 Like