int Count(Graph G)
{
int count=0;
for(v=0;v
if(!visited[v])
{
DFS(G,v);
count++;
}
}
return count;
}
void DFS(Graph G, int)
{
visited[v]=true;
for(w=FirstAdjVex(G,v); w; w=NextAgjVex(G,v,w))
{
if(!visited[w]) DFS(G,w)
}
}