UVA 10457 Magic Car

Source: Internet
Author: User

Test instructions: N points, M road, each start and stop car need x, y energy, give each road and the speed of the road, the additional energy consumption is the maximum difference of all the crossing, each given the start and end, the output of the minimum energy

Analysis: Start and end of the energy must be consumed, and then is to seek the minimum speed between the starting point and the end of the difference, Purple Book 11 is the problem is to find the smallest bottleneck tree, and this condition is similar, the difference is to generate a tree, inspired by the problem, all sides in accordance with the speed of the order

Then the piece raises the edge, uses and checks the set to determine whether X, y two is connected.

#include <algorithm>#include<cstdio>#include<cstring>#include<iostream>using namespacestd;Const intmaxn=1005;structnode{intu,v,w; BOOL operator< (node& R)Const{        returnw<R.W; }}P[MAXN];intF[MAXN];intFindintx) {    returnf[x]==x?x:f[x]=find (F[x]);}intMain () {intN,m,u,v,w,ans;  while(~SCANF ("%d%d",&n,&m)) {         for(intI=0; i<m;i++) scanf ("%d%d%d",&p[i].u,&p[i].v,&P[I].W); Sort (p,p+m); scanf ("%d%d",&u,&v); Ans=u+v; scanf ("%d",&W);  while(w--){            inttmp=0x3f3f3f3f; scanf ("%d%d",&u,&v);  for(intI=0; i<m;i++){                 for(intj=1; j<=n;j++) f[j]=J;  for(intj=i;j<m;j++){                    intt1=find (P[J].U); intT2=find (P[J].V); if(T1!=T2) f[t1]=T2; if(Find (u) = =Find (v)) {tmp=min (tmp,p[j].w-P[I].W);  Break; }}} printf ("%d\n", ans+tmp); }    }    return 0;}
View Code

UVA 10457 Magic Car

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.