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

Автор competitivecoder, история, 9 лет назад, По-английски

I have been trying to debug my code for hours still don't know why my code is printing wrong answer.Actually I am trying to find number of connected components of a graph.Please help me in this regard.Thank you _/_ .Question link

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

»
9 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

You have already transformed your input from 'A'-'Z' to 0-25 at

        while((cin>>s))
        {  
            G[s[0]-'A'].pb(s[1]-'A');
            G[s[1]-'A'].pb(s[0]-'A');
        }

but in dfs you try transform data too:

        if(color[G[s][i] - 'A']==-1)
        {  
            dfs((G[s][i] - 'A') ,col);
        }

So you need to remove "-A" transform in dfs and your code will be ok:

        if(color[G[s][i]]==-1)
        {  
            dfs(G[s][i],col);
        }