链式前向星建图 模板

 1 struct Edge{
 2     int v,next;
 3 }edge[maxn<<1];
 4 int cnt,head[maxn];
 5 void add(int u,int v){   //链式前向星
 6     edge[cnt].v=v;
 7     edge[cnt].next=head[u];
 8     head[u]=cnt++;
 9 }
10 void init(){ memset(head,-1,sizeof(head)); cnt=0; }
11 
12 for(int i=head[u];i!=-1;i=edge[i].next){
13         int x=edge[i].v;
14         if(x!=pre){
15             sz[u]+=dfs(x,u);
16         }
17     }
View Code

GG

猜你喜欢

转载自www.cnblogs.com/qq-1585047819/p/11940322.html