Idea: feel a bit like violence ah, anyway I feel very violent, such as beg d[i][j], use this method to ask, directly consider will not go through a point K (k is any point), and finally get the minimum value
Look at the code
#include <iostream>#include<cstdio>#include<cstring>#include<stdio.h>#include<string.h>#include<cmath>#include<math.h>#include<algorithm>#include<Set>#include<queue>#include<map>typedefLong Longll;using namespacestd;Constll mod=1e9+7;Const intmaxn=1e3+Ten;Const intmaxk= -+Ten;Const intmaxx=1e4+Ten;Constll maxe= ++Ten;#defineINF 0x3f3f3f3f3f3fintV,e;ll D[MAXN][MAXN];//Cost[u][v] Represents the weight of the Edge (U,V), does not exist when initializing infinity, the same point is 0BOOLVIS[MAXN];voidsolve () { for(intI=0; i<v;i++) { for(intj=0; j<v;j++) { for(intk=0; k<v;k++) D[j][k]=min (d[j][k],d[j][i]+D[i][k]); } } for(intI=0; i<v;i++) { for(intj=i+1; j<v;j++) cout<<i<<" "<<j<<" "<<d[i][j]<<" "<<Endl; }}intMain () {Ios::sync_with_stdio (false); CIN>>v>>e; for(intI=0; i<v;i++) { for(intj=0; j<v;j++) D[i][j]=INF; D[i][i]=0; } intA,b,va; for(intI=0; i<e;i++) {cin>>a>>b>>va; D[A][B]=va; } solve (); return 0;}
Floyed-warshall algorithm (to find the shortest distance between any two points)