int e[N],ne[N],h[N],idx,w[N]; void add(int a,int b,int c){ e[idx]=b; w[idx]=c; ne[idx]=h[a]; h[a]=idx++; }