HDU 4786 Fibonacci Tree (2013 Chengdu 1006) minimum spanning trees + Fibonacci

Source: Internet
Author: User

Test instructions: Ask if there is a number of white edges in the spanning tree that match the Fibonacci number.

Idea: white edge black edge of each priority to find the minimum spanning tree, and statistical white edge in two cases of the number, and finally judge this interval can be. Be careful not to connect at first.

1#include <stdio.h>2#include <algorithm>3#include <string.h>4#include <cmath>5 #defineLL Long Long6 using namespacestd;7 intt,n,m;8 inttot;9 intf[100010];Ten structNode { One     intu,v,c; A} edge[100010]; - intf[100010]; - voidinit () { thef[0]=1; -f[1]=1; -tot=1; -      while(f[tot]<=100010) { +f[tot+1]=f[tot]+f[tot-1]; -tot++; +     } A } at  - intFINDD (intx) { -     if(f[x]==-1)returnx; -     Else returnf[x]=findd (f[x]); - } - BOOLCMP1 (node A,node b) { in     returna.c<B.C; - } to BOOLCMP2 (node A,node b) { +     returnA.c>B.C; - } the intMain () { *scanf"%d",&t); $     intcas=0;Panax Notoginseng init (); -      while(t--) { thescanf"%d%d",&n,&m); +cas++; A          for(intI=0; i<m; i++) { thescanf"%d%d%d",&edge[i].u,&edge[i].v,&edge[i].c); +         } -Sort (edge,edge+m,cmp1); $memset (f,-1,sizeof(F)); $         intCnt=0; -          for(intI=0; i<m; i++) { -             intx=findd (edge[i].u); the             inty=findd (EDGE[I].V); -             if(x!=y) {Wuyif[x]=y; the                 if(edge[i].c==1) -cnt++; Wu             } -         } About         intlow=CNT; $Cnt=0; -memset (f,-1,sizeof(F)); -Sort (edge,edge+m,cmp2); -          for(intI=0; i<m; i++) { A             intx=findd (edge[i].u); +             inty=findd (EDGE[I].V); the             if(x!=y) { -f[x]=y; $                 if(edge[i].c==1) thecnt++; the             } the         } the         intHigh=CNT; -         intflag=0; in          for(intI=1; i<=n; i++) { the             if(Findd (1)!=findd (i)) { theflag=1; About                  Break; the             } the         } the         if(flag) { +printf"Case #%d:no\n", CAs); -             Continue; the         }BayiFlag =false; the          for(inti =0; I <= tot; i++) the             if(F[i] >= low && f[i] <=High ) -Flag =true; -         if(flag) theprintf"Case #%d:yes\n", CAs); the         Elseprintf"Case #%d:no\n", CAs); the  the     } -     return 0; the}
View Code

HDU 4786 Fibonacci Tree (2013 Chengdu 1006) minimum spanning trees + Fibonacci

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.