前向星&链式前向星

参考博文:

https://blog.csdn.net/acdreamers/article/details/16902023

前向星

len[i]以i为起点的边在数组中的存储长度

head[i]以i为边集在数组中的第一个存储位置

链式前向星

 1 struct node
 2 {
 3     int next;//与第i条边同起点的下一条边的存储位置
 4     int to;//第i条边终点
 5     int w;//第i条边权值
 6 };
 7 //head[i]以第i条边为起点的第一条边的存储位置
 8 //head[]一般初始化为-1
 9 void add(int u,int v,int w)
10 {
11     node[cnt].w=w;
12     node[cnt].to=to;
13     node[cnt].next=head[u];
14     head[u]=cnt++;
15 }

猜你喜欢

转载自www.cnblogs.com/zuiaimiusi/p/10787499.html