首页 > 其他 > 详细

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

时间:2020-05-25 19:01:25      阅读:47      评论:0      收藏:0      [点我收藏+]

链式前项星:

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))

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

原文:https://www.cnblogs.com/Vikyanite/p/12960200.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!