链式前向星
优点
空间需求最小,利用率高,访问效率 较邻接表 低
原理
head[i]表示以i为起点的第一条边的存储位置
其中 edge[i].to 表示第i条边的终点 , edge[i].next表示与第i条边同起点的下一条边的存储位置 , edge[i].w为边权值。
int cnt=0;
void add(int u,int v,int w)
{
edge[cnt].w = w;
edge[cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt++;
}