ll@N,@M;int A[M],B[],p[],W[N],L,V[2M];mapC;weightedUnionFindU{'m',N,1};rep(j,M){ll@--(u,v),@w;if(U(u,v,w)||U.diff(u,v)==w)A[j]=u,B[j]=v,W[j]=w,C[{u,v}]=C[{v,u}]=j;else{graph g;g.setEdge(N,j,A,B);*p=j;if(L=g.shortestPath(v,u,V)+1)REP[V,i](t,L-1)w+=t==A[M=p[i+1]=C[{t,V[i+1]}]]?W[M]:-W[M];else break;wtLn(L,u+1);if(w<0)REP(i,L/2)swap(p[i],p[L-i-1]);wt(p(L)+1);return 0;}}wt(-1);