码迷,mamicode.com
首页 > 其他好文 > 详细

【模板】邻接链表

时间:2017-07-31 10:12:37      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:int   链表   起点   read   bsp   ++i   表示   null   max   

int n,m; //n表示点数,m表示边数
int first[maxn]; //first数组代表一个点所指向的边
int u[maxm],v[maxm],w[maxm],next[maxm]; //u表示边的起点,v表示边的终点,w表示边的权值
void read_graph() { //初始化邻接链表,即得到最初的图
    scanf("%d %d",&n,&m); //读入n,m
    for(int i=0;i<n;++i) first[i]=-1; //将first数组全部置为-1,即null
    for(int e=0;e<m;++e) { //读入每条边
        scanf("%d %d %d",&u[e],&v[e],&w[e]); //读入每条边的起点,终点,权值
        next[e]=first[u[e]]; //让边指向边的起点所指向的边
        first[u[e]]=e; //让点指向本条边
    }
}

【模板】邻接链表

标签:int   链表   起点   read   bsp   ++i   表示   null   max   

原文地址:http://www.cnblogs.com/Mr94Kevin/p/7261379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!