Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Count number of nodes in each connected part of an undirected unweighted graph

void DFS(int start, vector<int> v[],vector<int> &visited, int &count)
{
  visited[start] = 1;
  count++;
  for(int i= 0; i<v[start].size(); ++i)
  {        
    if(visited[v[start][i]] == 0)
        DFS(v[start][i], v, visited);        
  }    
}
---------------------------------------------------
  for(int i=1;i<=n;++i)
{
  if(visited[i] == 0 )
  {
     connected++;
     int count=0;
     DFS(i,v,visited,count);
     cout<<"This component has "<<count<<" nodes"<<"
";
  }        
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to calculate each row with on change table <td<input jquery 
Javascript :: Code is valid JSON equivalent of the key/value pair shown that also preserves the original value: UPC: 043875 
Javascript :: get the first value when mapping through the array 
Javascript :: No provider for HTTP! { HTTP Native} 
Javascript :: p5js unset fill 
Javascript :: java script num toSting syntax eror 
Javascript :: When you run JavaScript in a Node.Js application, elements in a Node.JS Stack actually executes the JavaScript: 
Javascript :: image popup js close button 
Javascript :: dom-to-image bad quality 
Javascript :: javascript apexcharts to base 64 image 
Javascript :: benchmark ram usage angular 
Javascript :: jquery dialog button text set by variable 
Javascript :: int cating javascript 
Javascript :: javascript seo url parameters 
Javascript :: react native whatsapp integration 
Javascript :: applescript show function keys 
Javascript :: vscode coderunner does not find python library 
Javascript :: ajax data does not support alphabets 
Javascript :: react open on different url instead of localhost 
Javascript :: how to new tab disable after hit enter in javascript 
Javascript :: how to assign bootstrapswitch using jquery 
Javascript :: regex changing before last dot value 
Javascript :: js im mobile hover id 
Javascript :: how to trim dates in react 
Javascript :: strip js for subscription 
Javascript :: chunks bug vue js 
Javascript :: vue slot events 
Javascript :: mongodbClint express 
Javascript :: puppeteer print page numbers after second page 
Javascript :: initialization failed for block pool registering (datanode uuid unassigned) service to exiting 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =