What should i apply dfs or bfs in FIND THE ISLAND Problem? Why?

@vivek96 If you just call the dfs function once then it will only perform dfs in one component of the graph.

If there are more than one components then we will have to iterate and run dfs starting from other vertices too.

1 Like

sorry,its not your fault but im unable to understand the concept of components.feeling bad!

DFS : to identify a single component.
Re-iteration of the loop : to find out the nodes which are not connected to the previous component found out and search again.

@shraeyas Sorry I wasn’t able to figure out the bug but seems like that Map is causing problems. I’m more of a Java/Python user so can’t help much.

@ssaxena36 no problem :slight_smile:

im getting sigsigv,CodeChef: Practical coding for everyone

@vivek96 you have declared the graph wrong.

It should be

vector<vector > graph(2001);

but working fine on local.

now getting WA.lol

Check the for loop you have in your main() function, it should be:

for(int i=1;i<=n;i++)

You missed the equal sign.

i corrected the code,but WA is still,u got AC?

Not yet :stuck_out_tongue:

4 WA…huh

now i tried accepted solution,it also gives wa.@admin please look at this matter,i think file issue

we all are getting wa.i think file issue