变量
- int head[x]:节点 x 的第一条边的编号,没有则为 0。
- int nxt[i]:编号为 i 的边在邻接表中的下一条边的编号。
- int ver[i]:编号为 i 的边指向的点。
- int edge[i]:编号为 i 的边的边权。
- int tot:最大的编号的边的编号,在运用“成对变换”求反边时初值常为 1。
函数
- void add(int x,int y,int z):新建一条边权为 z 的有向边 x→y。
代码
int head[N],ver[N<<1],edge[N<<1],nxt[N<<1],tot;
void add(int x,int y,int z){
ver[++tot]=y,edge[tot]=z,nxt[tot]=head[x],head[x]=tot;
}
高级版本
template<const int N,const int M>
struct Graph{
int head[N],ver[M],edge[M],nxt[M],tot;
void add(int x,int y,int z){
ver[++tot]=y,edge[tot]=z,nxt[tot]=head[x],head[x]=tot;
}
};
Graph<N,N<<1> G;