Rokua P1195 pocket of the Sky

Source: Internet
Author: User

P1195 pocket of Sky topic background

The little cedar sits in the classroom, looking through the pockets of the window to look at the pockets of the sky.

There are a lot of clouds floating there, looks very beautiful, the little Cedar wants to take off such beautiful several clouds, made cotton candy.

Title Description

Give you the number of clouds N, and then give you m relationship, indicating which clouds can be linked together.

Now the small cedar to make all the clouds into a K cotton candy, a cotton candy at least to use a cloud, the small cedar want to know how he even, the cost of the least.

Input output Format input format:

Each set of test data

The first line has three numbers n,m,k (1<=n<=1000,1<=m<=10000,1<=k<=10)

The next m number is three x,y,l per line, indicating that the x cloud and the Y cloud can be linked by the cost of L. (1<=x,y<=n,0<=l<10000)

30% of Data n<=100,m<=1000

Output format:

Output a row for each set of data, with only one integer representing the minimum cost.

If you can't even make a k marshmallow, output ' no Answer '.

Input and Output Sample input example # #:
3 1 21) 2 1
Sample # # of output:
1
Description

Xiamen one YMS Original

/*minimum Spanning tree runs the minimum spanning tree and ends when n-k edges are connected*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMaxx 1010#defineMAXN 10010using namespacestd;intn,m,w;intFa[maxx];structedge{int  from; intto ; intVal;} E[MAXN];intcmp (Edge A,edge b) {returna.val<B.val;}intFindintx) {    if(X!=fa[x]) fa[x]=find (fa[x]); returnfa[x];}voidUnionn (intXinty) {    intA=find (x); intb=find (y); FA[B]=A;}intMain () {scanf ("%d%d%d",&n,&m,&W);  for(intI=1; i<=m;i++) scanf ("%d%d%d", &e[i]. from,&e[i].to,&e[i].val); Sort (e+1, e+m+1, CMP);  for(intI=1; i<=n;i++) fa[i]=i; intsum=0, ans=0;  for(intI=1; i<=m;i++)    {        intX=e[i]. from; inty=e[i].to; if(Find (x)! =find (Y))            {unionn (x, y); Sum++; Ans+=E[i].val; }        if(SUM==N-W) Break; }    if(sum==n-w) printf ("%d\n", ans); Elseprintf"No answer\n"); return 0;}

Rokua P1195 Pocket of the Sky

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.