无向图的连通分量

邻接表存图,输出连通分量里顶点的下标:

#include 
using namespace std;
struct Edge{
    int to;
    Edge* next;
};
struct Vex{
    int id;
    Edge* first; 
}vex[100];
struct Tree{
    int id;
    Tree *child,*sibling;
};
void AddEdge(int u,int v){
    if(!vex[u].first){
        vex[u].first=new Edge;
        vex[u].first->to=v;
        vex[u].first->next=NULL;
        return;
    }
    Edge *p=new Edge;
    p->next=vex[u].first;
    p->to=v;
    vex[u].first=p;
}
int n;
void CreatGraph(){
    int u,v;
    cin>>n;
    for(int i=0;i>u>>v){
        AddEdge(u,v);
        AddEdge(v,u);
    }
}
bool vis[100];
void DFSTree(int v){
    for(Edge *e=vex[v].first;e;e=e->next){
        int w=e->to;
        if(!vis[w]){
            cout<

你可能感兴趣的:(无向图的连通分量)