bzoj1050 [HAOI2006] Travel COMF

Source: Internet
Author: User

Topic links

Kruskal minimum Spanning Tree

Sort the edges

A raised point plus edge, to be born into a tree update the answer can be

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <string>7#include <cmath>8#include <ctime>9#include <queue>Ten#include <stack> One#include <map> A#include <Set> - #defineRre (i,r,l) for (int i= (r); i>= (l); i--) - #defineRe (I,L,R) for (int i= (l); i<= (R); i++) the #defineClear (A, B) memset (A,b,sizeof (a)) - #defineDouin (x) scanf ("%lf", &x) - #defineStrin (x) scanf ("%s", (x)) - #defineLLin (x) scanf ("%lld", &x) + #defineInin (x) scanf ("%d", &x) - #defineCSC Main +typedef unsignedLong LongULL; AtypedefConst intCInt; attypedefLong LongLL; - using namespacestd; -CInt m=5001, n=501, p=9999999; - intYP () - { -     intx=0, f=0;CharCh=GetChar (); in      while(ch<'0'|| Ch>'9'){if(ch=='-') f=1; ch=GetChar ();} -      while(ch>='0'&&ch<='9') x*=Ten, x+=ch-'0', ch=GetChar (); to     returnf?-x:x; + } - structRA the { *     intx, y; $     Doublev;Panax Notoginseng }s[m]; - intFa[n],m,n,max,min,x,y,maxn,minn; the BOOLBo; + intFindintx) {returnx==fa[x]?x:fa[x]=find (Fa[x]);} A intComp (ra A,ra b) the { +     returna.v<B.V; - } $ voidMergeintXinty) $ { -     intQ=find (x), w=find (y); -     if(q!=w) fa[q]=W; the } - intgcdintAintb)Wuyi { the     intC; -      while(a%b) c=a%b,a=b,b=C; Wu     returnb; - } About intCSC () $ { -     DoubleF,total=P; -N=yp (), m=YP (); -Re (I,1, N) fa[i]=i; ARe (I,1, M) +     { theS[i].x=yp (), s[i].y=YP (); - Douin (S[I].V); $ merge (S[I].X,S[I].Y); the     } theX=yp (), y=YP (); the     if(Find (x)!=find (y)) {cout<<"Impossible";return 0;} theSort (s+1, s+m+1, comp); -Re (I,1, M) in     { thedo{0; maxn=s[i].v; theRe (J,1, N) fa[j]=J; About merge (S[I].X,S[I].Y); theRre (J,i,1) the         { thef=s[i].v/s[j].v; +             if(f>=total) {bo=0; Break;} - merge (S[J].X,S[J].Y); the             if(Find (x) = =find (y))Bayi             { theminn=s[j].v; thedo{1; -                  Break; -             } the         } the         if(!BO)Continue; theTotal=F; theMAX=MAXN; min=Minn; -     } the     if(max%min==0) {printf ("%d", max/min);return 0;} the     intD=gcd (max,min); theMax/=d,min/=D;94printf"%d/%d", max,min); the}

bzoj1050 [HAOI2006] Travel COMF

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.