HDU 1863 unblocked project (nine degrees OJ 1024)

Source: Internet
Author: User

Or the smallest spanning tree.

is to add a status check, can connect all the points.

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define INF 100000001
using namespace Std;
int a[1001]; struct LX {int x,y,c;}
L[5001];
    int intset (int n) {for (int i=0; i<=n; i++) a[i]=i;} int fa (int x) {if (x!=a[x]) X=fa (a[x]);
return a[x];
    } bool Cmpa (lx T1,LX T2) {return t1.c<t2.c;} int main () {int n,m; while (scanf ("%d%d", &n,&m), N) {for (int i=0;i<n;i++) scanf ("%d%d%d", &l[i].x,&l[i].y,
        &AMP;L[I].C);
        int x, y;
        Intset (m);
        Sort (L,L+N,CMPA);
        int ans=0;
            for (int i=0;i<n;i++) {X=FA (l[i].x);
            Y=FA (L[I].Y);
                if (x!=y) {ans+=l[i].c;
            A[y]=x;
        }} int s=0;
        for (int i=1;i<=m;i++) if (a[i]==i) s++;
        if (s>1) puts ("?");
    else printf ("%d\n", ans);
 }
}


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.