[Bzoj 1196] [Hnoi 2006] Highway construction problems

Source: Internet
Author: User

Title Link: http://www.lydsy.com:808/JudgeOnline/problem.php?id=1196

Can it be said that this is a bottleneck spanning tree problem?

Not very difficult to figure the topic, the idea is very ingenious ...

Binary spanning tree is the largest edge of the X, to determine whether such a spanning tree exists on the line ...

Each time the judgment is divided into two steps, first to limit the C1 is less than or equal to X, to determine whether the number of tree edges in the spanning tree is less than or equal to K, if greater than K, indicates that the spanning tree does not exist.

Again limit C2 is less than equal to X, because C2<C1, so this time C1 no tube, can add in the side are added, add the edge after the decision tree Edge is not n-1 (spanning tree connected to all the points), if not, indicates that the spanning tree does not exist.

#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < algorithm> #define Maxe 20050#define maxv 10050using namespace std;struct edge{int u,v,c1,c2;}    Edges[maxe];int n,m,k;int f[maxv];int findset (int x) {if (f[x]==x) return x; Return F[x]=findset (F[x]);}    BOOL judge (int x)//Set the maximum Benquan of the spanning tree to X, and determine if such spanning tree exists {for (int i=1;i<=n;i++) f[i]=i; int cnt=0;        The total number of tree edges in the current spanning tree for (int i=1;i<=m;i++)//There is a limit of C1 maximum value less than or equal to x in the spanning tree, but cannot be done, such a spanning tree does not exist {if (edges[i].c1>x) continue;        int Rootu=findset (EDGES[I].U), Rootv=findset (EDGES[I].V);            if (ROOTU!=ROOTV) {F[rootu]=rootv;        cnt++; }} if (cnt<k) return false;        There is a limit of C1 maximum of less than or equal to x in the spanning tree, but cannot be done so that the spanning tree does not exist for the (int i=1;i<=m;i++) {if (edges[i].c2>x) continue;        int Rootu=findset (EDGES[I].U), Rootv=findset (EDGES[I].V);            if (ROOTU!=ROOTV) {F[rootu]=rootv;        cnt++; }} if (cnt&LT;N-1) return false; On the previous basis, add the C2 maximum value in the spanning tree is less than or equal to X, but cannot do so, so the spanning tree does not exist return true;}    int main () {scanf ("%d%d%d", &n,&k,&m);    for (int i=1;i<m;i++) scanf ("%d%d%d%d", &AMP;EDGES[I].U,&AMP;EDGES[I].V,&AMP;EDGES[I].C1,&AMP;EDGES[I].C2);    int Lowerbound=1,upperbound=30000,ans;        while (lowerbound<=upperbound) {int mid= (lowerbound+upperbound)/2;            if (judge (mid)) {Ans=mid;        Upperbound=mid-1;    } else lowerbound=mid+1;    } printf ("%d\n", ans); return 0;}





[Bzoj 1196] [Hnoi 2006] Highway construction problems

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.