存图---链式前向星

void addedge(long long from,long long to,long long dis)//入边链式前向星 
{
    num_edge++;//编号
    edge[num_edge].next=head[from];//把next值改为此边编号
    edge[num_edge].to=to;//to和dis分别为对应的终点和长度
    edge[num_edge].dis=dis;
    head[from]=num_edge;//把这个边的始点的编号的head值改为前一个边的编号(指向)
}

遍历:

for(int i=head[u];i!=-1;i=edge[i].next)
{ .......
.......
}

前置:

int head[MAXN];  //初始化为-1
int num=0;
struct edg{
   long long int next,to,dis;
}edge[MAXN];
越自律,越自由
原文地址:https://www.cnblogs.com/ha-chuochuo/p/13522175.html