开始整理我的板子咯——持续更新中——

链式前项星:

struct E
{
    int to, w, next;
}edge[N];

//我这里习惯用1作为第一条边
int tot=1, head[N];

inline void add_edge(int u, int v, int w)
{
    edge[tot].to = v;
    edge[tot].w = w;
    edge[tot].next = head[u];
    head[u] = tot++;
}

//遍历代码
for (int i = head[u]; !i; i=edge[i].next)
{
    int v=edge[i].to;
    int w=edge[i].w;
    //to do something
}

这里的tot其实从0开始也是可以的,这样初始化就是memset(head,-1sizeof(head)), 遍历的终止条件就是~i ;

主要我其他都是初始化为0,所以就从1开始,这样的遍历条件就是!i,初始化就是memset(head,-0,sizeof(head))

猜你喜欢

转载自www.cnblogs.com/Vikyanite/p/12960200.html