BZOJ1196[HNOI2006] Highway construction problems

Source: Internet
Author: User

BZOJ1196[HNOI2006] Highway construction problems

Test instructions

Repair N-1 Road will be n points to connect, each point can be built a road can also be built a second-class highway, requires the first road must have K, requires the most cost of the road to spend the least.

Exercises

The first two minutes of the largest cost, and then decided: first in the premise of not producing the ring (with and check set maintenance) to make every road as far as possible to repair a road, if the last can not constitute a tree to consider the repair of the two-level highway.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 105006 using namespacestd;7 8 intn,k,m,u[maxn*2],v[maxn*2],c1[maxn*2],c2[maxn*2],mx,fa[maxn],cnt;9 intFindintx) {returnx==fa[x]?x:fa[x]=find (Fa[x]);}Ten BOOLCheckintLim) { OneInc (I,1, n) fa[i]=i; Cnt=0; AInc (I,1, m)if(c1[i]<=Lim) { -         intX=find (U[i]), Y=find (V[i]);if(x==y)Continue; Fa[y]=x; cnt++; -     } the     if(cnt<k)return 0; -Inc (I,1, m)if(c2[i]<=Lim) { -         intX=find (U[i]), Y=find (V[i]);if(x==y)Continue; Fa[y]=x; cnt++; -     } +     if(cnt<n-1)return 0;return 1; - } + intMain () { Ascanf"%d%d%d", &n,&k,&m); mx=0; atInc (I,1, M-1) scanf ("%d%d%d%d", &u[i],&v[i],&c1[i],&c2[i]), Mx=max (Mx,c1[i]), mx=Max (mx,c2[i]); -     intL=0, r=Mx,ans; -      while(l<=R) { -         intMid= (l+r) >>1; -         if(Check (mid)) ans=mid,r=mid-1;ElseL=mid+1; -     } inprintf"%d", ans);return 0; -}

20160531

BZOJ1196[HNOI2006] Highway construction problems

Related Article

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.