MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / DFS

Function DFS

Hackerrank_problems/Journey to the moon/solution.cpp:20–29  ·  view source on GitHub ↗

Function that returns number of nodes in the connected component having vertex u

Source from the content-addressed store, hash-verified

18
19// Function that returns number of nodes in the connected component having vertex u
20ll DFS(ll u, bool* visited,vector<ll>* graph){
21 visited[u]=true;
22 // initialize number of nodes to 1
23 ll cc = 1;
24 for(auto i: graph[u])
25 if(!visited[i])
26 // recursively add the number of nodes in the component for each directly connected node
27 cc += DFS(i,visited, graph);
28 return cc;
29}
30int main(){
31 fastio // for faster input/output
32

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected