Code failing test cases in BUGLIFE

I was solving BUGLIFE.

My code : https://ideone.com/Y2jdyz

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?

Edit:

Also, review the Output format carefully.

Edit2:

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

2 Likes

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 : https://ideone.com/Ubd5a4
Passes test cases, but gives WA. Where am I going wrong?

@anon21889647

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:

2 Likes

Got AC. Thanks @ssjgz @therealnishuz
My code : https://ideone.com/leDwOd (Just in case anyone wants)

1 Like