首页 > 编程知识 正文

poj 2485 Highways -----最小生成树。prim

时间:2023-05-04 10:22:33 阅读:57627 作者:3573

highways http://www.Sina.com/1000 ms http://www.Sina.com/65536 k http://www.Sina.com/15145http://www.Sina.com/7050信任字体权重: bold; color:#0000FF; '描述

The island nation of粗暴的发夹is perfectly flat. Unfortunately, 粗糙的发夹hasnopublichighways.sothetrafficisdifficultin粗糙的发夹. the粗糙的发夹ngovernmentisawareofthisproblem.they ' replanninicultion llbepossibletodrivebetweenanypairoftownswithoutleavingthehighwaysystem .粗糙的发夹ntownsarenumberedfrom1ton.each hi ghwayconeconeconece sfollowstraightlines.allhighwayscanbeusedinbothdirections.highwayscanfreelycrosseeer, butadrivercanonlyswitchbetweenhighwaysatatownthatislocatedattheendofbothhhighways.the粗糙的发夹ngovernmentwantstominimizethelendays built.However,theywanttoguaranteethateverytownishighway-reachablefromeveryothertown.input

thefirstlineofinputisanintegert,whichtellshowmanytestcasesfollowed。

thefirstlineofeachcaseisanintegern (3=n=500 ),whichisthenumberofvillages.thencomenlines, thei-thofwhichcontainsninntegern andthej-thofthesenintegersisthedistance [ 1,65536 ]

For each test case,youshouldoutputalinecontainsaninteger,whichisthelengthofthelongestroadtobebuiltsuchthatalllthevilllagesarecorecococor

13099069299001796921790样品输出

692 # include stdio.h # include string.hconstintmax=70000; int map[505][505],vir[505]; intprim(intn ); int main ()//Freopen(in.txt )、(r )、stdin ); int t,n,I,j; 扫描(' % d ',t ); while(t-- ) memset ) vir,0,sizeof ) vir ); scanf('%d ',n ); for(I=0; in; I ) for ) j=0; jn; j ) scanf('%d ',map[i][j]; printf('%dn ',prim(n ) ); }返回0; (intprim ) intn ) {int count=0,min,max=0,I,j,temp=n,next; int p[505]; p[0]=0; vir[0]=1; wile(--temp ) {min=MAX; for(I=0; i=count; I ) for(j=0; jn; j () if (! vir [ j ] map [ p [ I ] [ j ] min ] { min=map [ I ] [ j ]; next=j; }}}vir[next]=1; p优秀行人count]=next; if (最小最大)最大=min; //printf(%d%d%d(n ),count,next,max ); }返回最大值; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。