bool isBipartite = true;
void dfs(int node, int color) { vis[node] = color;
for(auto it: adj[node])
{
if(vis[it] == 0)
{
dfs(it, 3 - color);
}
if(vis[it] == vis[node])
{
isBipartite = false;
return;
}
}
}
can someone tell me what is wrong with this implementation i was doin building teams problem on cses
Auto comment: topic has been updated by Morg0th (previous revision, new revision, compare).
Your function looks correct to me. I think you assumed that the graph will have only $$$1$$$ connected component, which is wrong.
Also, it would be better if you shared your entire code, the problem can be anywhere after all.
https://cses.fi/problemset/task/1668 heres my whole solution https://pastebin.com/iePmu8tk
Unable to open link. Can you share the pastebin link of cses directly? You can go to your submission, there you will see a "Share your code to others" button below your code.