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