前向星&链式前向星

时间:2023-03-09 17:01:33
前向星&链式前向星

参考博文:

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

前向星

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

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

链式前向星

 struct node
{
int next;//与第i条边同起点的下一条边的存储位置
int to;//第i条边终点
int w;//第i条边权值
};
//head[i]以第i条边为起点的第一条边的存储位置
//head[]一般初始化为-1
void add(int u,int v,int w)
{
node[cnt].w=w;
node[cnt].to=to;
node[cnt].next=head[u];
head[u]=cnt++;
}