Finding a Star
Test instructions: Given a weighted graph, a path defined from one point to another is long as the maximum of all edge weights on the path and is given a four-point numberW,T1,T2,T3.
Find out a pointSand make it in toT1,t2 < Span class= "Mord" >,t3 three point shortest path maximum maximum or no path at all based on w Shortest path minimum.
Originally is to strengthen the data card Floyd, but also too late, Floyd no brain run again enumerate can. Note that this is a forward graph, and three of people are also considered human beings.
#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;#defineINF 0x3f3f3f3f#defineFP (i,a,b) for (int i=a;i<=b;++i)intdis[ the][ the],n,m,w,t1,t2,t3,ans=-1, maxc=-1, minc=0x7fffffff;intMain () {scanf ("%d%d",&n,&m); memset (DIS,0x3f,sizeof(DIS)); FP (i,1, N) dis[i][i]=0; FP (i,1, M) { intX,y,c; scanf ("%d%d%d",&x,&y,&c); Dis[x][y]=C; } fp (k,1, N) FP (i,1, N) FP (J,1, N)if(dis[i][j]>Max (Dis[i][k],dis[k][j]) dis[i][j]=Max (dis[i][k],dis[k][j]); scanf ("%d%d%d%d",&w,&t1,&t2,&T3); FP (i,1, N) { if(i==w| | i==t1| | i==t2| | i==t3| | Dis[w][i]>=inf)Continue; intdt=min (dis[t1][i],min (dis[t2][i],dis[t3][i)); if(dt>MAXC) {MAXC=DT; Ans=i; } Else if(dt==MAXC) { if(dis[w][i]<minc) {Minc=Dis[w][i]; Ans=i; }}} printf ("%d", ans); return 0;}
Eto's open T3 "Searching for Stars" (by super-level/test field WA Monsters)