链式前向星

来源:互联网 发布:搜索电影免费网络观看 编辑:程序博客网 时间:2024/05/12 18:46

#include<cstdio>

#include<cstdlib>

#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1000;
const int maxm=100;
int to[maxm],next[maxm],begin[maxm],p[maxm],w[maxm],e;
void add(int x,int y,int z){
    to[++e]=y;
    next[e]=begin[x];
    begin[x]=e;
    w[e]=z;
}
void dfs(int x){
    for(int i=begin[x];i;i=next[i])
        if(!p[to[i]])
            dfs(to[i]);
}
int main(){
int i,j,k,m,n;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        add(x,y,z);
        add(y,x,z);
}
dfs(1);
return 0;
}
1 0
原创粉丝点击