Start on the last day and add the edge forward.
The side of the same day is added to the graph, and after the addition, check whether the number of collections and not in addition to the previous changes.
If there is a change, the answer is +1.
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespacestd;Const intmaxn=100000+Ten;intn,m;structedge{intU,v,c;} E[MAXN];intF[MAXN];BOOLcmpConstEdge&a,Constedge&b) { returnA.c>B.C;}intFind (intx) { if(X!=f[x])returnf[x]=Find (f[x]); returnf[x];}intMain () { while(~SCANF ("%d%d",&n,&m)) { for(intI=1; i<=m;i++) scanf ("%d%d%d",&e[i].u,&e[i].v,&e[i].c); Sort (e+1, e+1+m,cmp); for(intI=1; i<=n;i++) f[i]=i; intL=1, r=1, ans=0; while(1) { while(1) { if(E[R].C==E[L].C) r++; Else Break; } intD=0; for(inti=l;i<=r-1; i++) { intfu=Find (E[I].U); intfv=Find (E[I].V); if(FU!=FV) d=1, f[fu]=FV; } ans=ans+D; L=r;if(l>m) Break; } printf ("%d\n", ans); } return 0;}
Nyoj 925 troubles of the King