终极图模板
好了,这可能是终极的图模板了。
struct Graph{
struct Edge{
int to, next; Graph *bel;
inline int operator *(){ return to; }
Edge& operator ++(){
return *this=bel->edge[next]; }
};
void addedge(int x, int y){
Edge &e=edge[++cntedge];
e.to=y; e.next=fir[x];
fir[x]=cntedge; e.bel=this;
}
void reset(){
cntedge=0; memset(fir, 0, sizeof(fir)); }
Edge& getlink(int x){
return edge[fir[x]]; }
Edge edge[maxm*2];
int cntedge, fir[maxn];
}g;
(日文不懂装懂)