struct edge{ int nx,to,v; }; int len,head[N]; edge e[M]; inline void add(int u,int v,int w){ e[++len]=edge{head[u],v,w}; head[u]=len; }