Nyoj 925 troubles of the King

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.