The island nation of丰富的鱼is perfectly flat. Unfortunately, 丰富的鱼hasnopublichighways.sothetrafficisdifficultin丰富的鱼. the丰富的鱼ngovernmentisawareofthisproblem.they’replanningtobubultin ibletodrivebetweenanypairoftownswithoutleavingthehighwaysystem。
丰满的鱼ntownsarenumberedfrom1ton.eachhighwayconnectsexactlytwotowns.allhighwaysfollowstraightlines.allhighwayscanbeusedinbows crosseachother,butadrivercanonlyswitchbetweenhighwaysatatownthatislocatedattheendofbothhhhighways。
The丰满的鱼ngovernmentwantstominimizethelengthofthelongesthighwaytobebuilt.however,theywanttoguaranteeeethateverytownishighway---- thed
thefirstlineofinputisanintegert,whichtellshowmanytestcasesfollowed。
thefirstlineofeachcaseisanintegern (3=n=500 ),whichisthenumberofvillages.thencomenlines, thei-thofwhichcontainsninntegern andthej-thofthesenintegersisthedistanceshouldbeanintegerwithin 1, 65536] ) betweenvillageiandvillagej.thereisanemptylineaftereachtestcase.http://www.Sina.com /
For each test case,youshouldoutputalinecontainsaninteger,whichisthelengthofthelongestroadtobebuiltsuchthatalllthevilllagesarecorecococor
1
3
0 990 692
990 0 179
692 179 0 Input
692
Hint
Huge input,scanf is recommended。
Output
# include iostream # include cstdio # includealgorithmusingnamespacestd; 泰普德夫龙龙LL; 常数int maxx=1e57; int x[maxx],pre[maxx]; 结构节点{ int x,y; int s; }bb[maxx]; OOLCMP(nodea,node b ) { return a.sb.s; }intfind(intx ) if ) x!=pre[x]({pre[x]=find(pre[x] ); }返回pre [ x ]; }voidjoin(intx,int y ) intFX=find ) x,fy=find(y ) y; IF (福克斯!=fy ) pre[fx]=fy; (}int main ) ) { int t; 扫描(' % d ',t ); while(t---- ) { int n,ss; int ans=0; scanf('%d ',n ); for(intI=1; i=n; I ) pre[i]=i; for(intI=1; i=n; I ) for(intj=1; j=n; j ) scanf('%d ',ss ),bb[ans].x=i,bb[ans].y=j,bb[ans ].s=ss; sort(bb,bb ans,cmp ); int temp=-1; for(intI=0; ians; I ) if(find(bb[I].x )!=find(bb[I].y ) ) if ) temp=bb[i].s ) temp=bb[i].s; join(bb(I ).x,bb ) ) I ).y; } } cout tempendl; }返回0; }