Originally wanted to write a bfs to let him follow the outcome of the climb to the corner of the decision can not determine the order
And then I find out that there are extra sides that don't omit to write an O (n^3) to erase the extra edges, which is not as good as Floyd.
See Shang Seniors write is topological sequence also can solve and in understanding his article when the IQ offline Floyd didn't recognize
Finally I wrote a (standard) Floyd gorgeous WA and then find out is I j K sequence written bad Hmm, the original algorithm or to review the
Have time to learn more about topological sequencing solutions
#include <cstdio>#include<cstring>intMain () {intmap[ the][ the]; intN, M; memset (Map,0,sizeofmap); scanf ("%d%d", &n, &m); while(m--){ intA, B; scanf ("%d%d", &a, &b); MAP[A][B]=1; } for(inti =1; I <= N; i++){ for(intj =1; J <= N; J + +){ for(intK =1; K <= N; k++){ if(Map[j][i] &&Map[i][k]) {Map[j][k]=1; } } } } intres =0; for(inti =1; I <= N; i++){ intCount =0; for(intj =1; J <= N; J + +) {Count+ = Map[i][j] +Map[j][i]; } if(count = = N-1) res++; } printf ("%d\n", RES); return 0;}
Kuangbin_shortpathh (POJ 3660)