Question:
There are t paths. Take n steps from s to e to find the shortest path.
Ideas:
I read someone else's...
Let's take a look at Floyd's core idea: edge [I] [j] = min (edge [I] [j], edge [I] [k] + edge [k] [j])
The shortest path from I to j is the direct path from I to j or the indirect path passing through k points, but the update of the matrix is always affected by the last update.
If each update is stored in a new matrix, does edge [I] [k] + edge [k] [j] indicate the path passing through only two edges of three vertices?
Min (edge [I] [j], edge [I] [k] + edge [k] [j]) indicates the Shortest Path passing through the two edges of only three points.
#include
#include
#includeusing namespace std;typedef long long LL;const int MAXN=256;const int INF=0x3fffffff;int num[MAXN<<2];int n,t,s,e,cnt;struct Matrix{LL data[MAXN][MAXN];Matrix(){for(int i=0;i
>=1;}}int main(){cnt=0;scanf(%d%d%d%d,&n,&t,&s,&e);int from,to,val;memset(num,-1,sizeof(num));for(int i=0;i