int hd[N], nx[N], v[N], w[N], m; void addedge(int _u, int _v, int _w) { nx[_u] = hd[_u], hd[_u] = ++m, v[m] = _v, w[m] = _w; }