The topic probably means: input n,m,n represents n points, then enter the distance between n points (N*n matrix), then M inquiry, input a,b,c if there is a C point between the shortest path between a and B, output yes, otherwise the output no
The game did not make it out, after the game sail brother a on-demand to know .... When I write, I directly use the Floy algorithm to find the distance and record the path. Then tle to die ... I was surprised that the data n,m are less than 100, how can tle ah ... The Pit Daddy Ah ... I have always suspected that it is not using other algorithms .... Sail brother said I recorded the path is only a path in the correct path, such as 1-3 Direct shortest path is 2, but may be added up to 2, but you recorded the path is 1-3 instead of the answer is not the right .... Suddenly understand,,. Why didn't I think of Qaq ... And tle is not necessarily time-out ah, there may be a variety of wonderful mistakes caused by ....
Correct solution:
How to determine whether the minimum path can have a C point, as long as the judge d[a][b] = = D[a][c] + d[c][b] equality exists, not equal to the existence of ...
#include < iostream> #include <cstdio> #include <cstring>using namespace Std;int d[150][150];int w[150][150];const int INF = 127;int Main () {int n,m; #ifdef XXZ freopen ("In.txt", "R", stdin); #endif//Xxz while (cin>>n>>m) {memset (d,inf,sizeof (d)); for (int i = 1, i <= N; i++) for (int j = 1; J <= N; j + +) cin>>d[i][j]; for (int k = 1, k <= N; k++) for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +) D[i][j] = min (D[i][j], d[i][k] + d[k][j]); while (m--) {int start,end,mid; cin>>start>>end>>mid; if (D[start][mid] + d[mid][end] = = D[start][end]) cout<< "Yes" <<endl; else cout<< "No" <<endl; }} return 0;}
Ingenious use of Floyd algorithm