前向星

昨天又把前向星看了一遍,,,

前向星的加边函数是这样的

struct node
{
    int to;int next;
}edge[maxn];

void add(int u,int v)
{
    edge[cnt].to=v;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}

void init()
{
    cnt=0;
    memset(head,-1,sizeof(head));
}

遍历的循环是这样的:

for(int i=head[u];i!=-1;i=edge[i].next)
{
    int k=edge[i].v;
}
原文地址:https://www.cnblogs.com/qioalu/p/5202651.html