【模板】前向星

建立:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct EDGE{
int next;
int to;
int weight;
};
EDGE graph[MAXM];
int head[MAXN]={0},nume=-1;

void adde(int f,int t,int w){
graph[++nume].next=head[f];
graph[nume].to=t;
graph[nume].weight=w;
head[f]=nume;
}
memset(head,-1,sizeof(head));//不能忘

遍历:

1
2
3
4
for(i=head[now];i!=-1;i=graph[i].next){
graph[i].weight...
graph[i].to...
}

dinic中的反向弧操作:
规定邻接表数组从0开始、两下标可以表示为(i,i^1)