Блог пользователя Morg0th

Автор Morg0th, 10 месяцев назад, По-английски

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

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
10 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Morg0th (previous revision, new revision, compare).

»
10 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.