daily pastebin goal
46%
SHARE
TWEET

Depth First Search

keverman Jan 16th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int DFS(int u)
  2. {
  3.     if(!visited[u])
  4.     {
  5.         visited[u] = true;
  6.        
  7.         if(edges[u].size() == 1 && visited[edges[u][0]])
  8.             quantity[u] = 1;
  9.        
  10.         else
  11.             for(unsigned int i = 0; i < edges[u].size(); i++)
  12.                 quantity[u] += DFS(edges[u][i]);
  13.                
  14.         return quantity[u];
  15.     }
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top