title: Finding no. of strongly connected components - wrong answer by my code
body: <p>I was trying to find no. of strongly connected components in a graph. I wrote the below algo but it is failing. The count variable stores the no.of connected components. Count variable is incremented:</p>
  <ol>
  <li>when any unvisited vertex is found (line 1 in code) and then for that vertex dfs is performed</li>
  <li>when no edge going out of the subtree with the lowest arrival time lower than the arrival time of the vertex itself is found (line 2 in code)</li>
  </ol>
  <p>I have tried to comment my code. Please tell where I am wrong.</p>
  <pre><code>    int noOfStronglyConnectedComp(int V, vector&lt;int&gt; adj[])
      {
          vector&lt;bool&gt; visited(V,false);
          vector&lt;int&gt; arr(V);    //arrival time of a vertex: when a vertex is first reached
          int timer=0;           //allocated to arrival time
          int count=0;           //stores no. of connected components
          for(int i=0;i&lt;V;i++)
          {
              if(!visited[i])
                 { 
                     count++;  //line 1
                     dfs(i,adj,visited,arr,timer,count,i);
                 }
          }
          return count;
          
      }
      int dfs(int source,vector&lt;int&gt; adj[], vector&lt;bool&gt; &amp;visited,vector&lt;int&gt; &amp;arr, int &amp;timer, int &amp;count,int parent)
      {
          visited[source]=1;        //node marked visited
          arr[source]=timer++;      //arrival time is set
          int lowest=arr[source];   //lowest stores the edge going out of the subtree with the lowest arrival time
          for(int i=0;i&lt;adj[source].size();i++)
              {
                  if(!visited[adj[source][i]])
                      lowest=min(lowest,dfs(adj[source][i],adj,visited,arr,timer,count,parent));
                  else
                      lowest=min(lowest,arr[adj[source][i]]);
              }
          if(lowest==arr[source] &amp;&amp; source!=parent) 
          count++;    //line 2
          return lowest;    
      }
  </code></pre>