struct Node { int from,to,next; }edge[MAXM]; int tol; int head[MAXN]; void init() { tol=0; memset(head,-1,sizeof(head)); } void addedge(int u,int v) { edge[tol].from=u; edge[tol].to=v; edge[tol].next=head[u]; head[u]=tol++; } for(int i=head[u];i!=-1;i=edge[i].next) { }