[BZOJ4452] Export Estimate

Source: Internet
Author: User

For all points with a degree of 2, the number is reduced by 1, and the edge is reduced by 1

However, the need for a simple ring

We put the inquiry and the side all from the big to the small sort, and then the ice fried chicken maintenance

ans_n=n-0 Point-out of 2 points + simple ring, ans_m= added Edge-2 point + simple ring

1#include <cstdio>2#include <algorithm>3 using namespacestd;4 #defineMP Make_pair5 #defineFIR First6 #defineSEC Second7 #defineMAXN 3000058 structroad{9     intu,v,w;Ten     BOOL operator< (Road t)Const{returnW>T.W;} One }R[MAXN]; Apair<int,int>QRY[MAXN],ANS[MAXN]; - intFA[MAXN],SZ[MAXN],ER[MAXN],DU[MAXN]; - intN,m,q,zero,two,cir; the intGfintx) {returnFa[x]=fa[x]==x?X:GF (fa[x]);} - voidUnintXinty) { -fa[y]=x; -sz[x]+=sz[y],er[x]+=Er[y]; + } - intAdd_du (intx) { +     intf=GF (x); A     if(du[x]==2){ at         if(Er[f]==sz[f]) cir--; ---, er[f]--; -     } -     if(!du[x]) zero--; -du[x]++; -     if(du[x]==2){ intwo++,er[f]++; -         if(Er[f]==sz[f]) cir++; to     } +     returnF; - } the intMain () { *scanf"%d%d",&n,&m); $      for(intI=1; i<=m;i++)Panax Notoginsengscanf"%d%d%d",&r[i].u,&r[i].v,&R[I].W); -Sort (r+1, r+1+m); thescanf"%d",&q); +     intx; A      for(intI=1; i<=q;i++){ thescanf"%d",&x); +qry[i]=MP (X,i); -     } $Sort (qry+1, qry+1+q); $      for(intI=1; i<=n;i++) -sz[i]=1, er[i]=0, fa[i]=i; -     intlst=1; thezero=n,two=0, cir=0; -      for(inti=q;i;i--){Wuyi          for(intj=lst;j<=m&&r[j].w>=qry[i].fir;j++,lst=j) { the             intF1=add_du (r[j].u), f2=Add_du (R[J].V); -             if(f1!=F2) un (F1,F2);  Wu         } -ANS[QRY[I].SEC]=MP (N-zero)-two+cir, (lst-1)-two+Cir); About     } $      for(intI=1; i<=q;i++) -printf"%d%d\n", ans[i].fir,ans[i].sec); -     return 0; -}
View Code

[BZOJ4452] Export Estimate

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.