title: What's Wrong In My DFS Code?
body: <p>I have tried to Implement Recursive DFS as I found at TH Cormen's Book . I implemented the Algorithm . But the program Crashed . Here is my Code:</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  vector&lt;int&gt;graph[100];
  int tim;
  int start[100], finish[100], path[100], color[100];
  
  void DFS_Visit(int u)
  {
      color[u] = 0;
      tim = tim + 1;
      start[u] = tim;
      for(int i=0; i&lt;graph[u].size(); i++)
      {
          int v = graph[u][i];
          if(color[v]=-1)
          {
              path[v] = u;
              DFS_Visit(v);
          }
      }
      color[u] = 1;
      tim = tim + 1;
      finish[u] = tim;
  }
  
  int main()
  {
      int nodes, edges, u, v;
      cin&gt;&gt;nodes&gt;&gt;edges;
      for(int i=0; i&lt;edges; i++)
      {
          cin&gt;&gt;u&gt;&gt;v;
          graph[u].push_back(v);
          graph[v].push_back(u);
      }
      for(int i=1; i&lt;=nodes; i++)
      {
          color[i] = -1;
          path[i] = -1;
          //cout&lt;&lt;'1'&lt;&lt;endl;
      }
      tim = 0;
      for(int i=1; i&lt;=nodes; i++)
      {
          //cout&lt;&lt;'1'&lt;&lt;endl;
          if(color[i]==-1)
          {
              DFS_Visit(i);
          }
      }
      for(int i=1; i&lt;=nodes; i++)
      {
          printf("Node %d: Starting_Time: %d || Finishing Time: %d\n", i, start[i], finish[i]);
      }
      return 0;
  }
  </code></pre>
  
  <p>Can anyone please learn me What's wrong with my Code? What to do to resolve this Problem . I have written the Code as TH Cormen's Algorithm Book .</p>