图的邻接表存储

图的邻接表存储

struct Edge
{
    int v;
    ll w;
    Edge *next;
};Edge e[maxn*10];

void add_edge(int u,int v,ll w) ///插入邻接表的首部而非尾部,避免遍历
{
    Edge *pre=&e[u];
    Edge *p=(Edge*)malloc(sizeof(Edge));
    p->v=v;p->w=w;
    p->next=pre->next;
    pre->next=p;
}
    //遍历
        for(Edge *p=e[u].next;p!=NULL;p=p->next)//遍历结点u的每条出边
View Code
没有AC不了的题,只有不努力的ACMER!
原文地址:https://www.cnblogs.com/--560/p/4410318.html