为什么WA了?
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#define MA 0x5fffff
using namespace std;
void floyd(int d[21][21],int n){
int i,j,k;
for(i=0;i<n;i++){
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(d[j][k]>d[j][i]+d[i][k]) d[j][k]=d[j][i]+d[i][k];
}
/* for(i=0;i<n;i++)
for(j=0;j<n;j++)
printf("distance between %d and %d is %d\n",i+1,j+1,d[i][j]);
*/
}
int main(){
int i,j,n,m,y,x;
int d[21][21],t;
//printf("%d\n",MA);
while(scanf("%d",&n)==1){
for(i=0;i<n;i++)
for(j=0;j<n;j++){
scanf("%d",&t);
if(t&&j>i) d[i][j]=t;
else d[i][j]=MA;
}
floyd(d,n);
scanf("%d",&m);
while(m--){
scanf("%d %d",&x,&y);
if(d[x-1][y-1]<MA) printf("%d\n",d[x-1][y-1]);
else printf("No\n");
}
}
return 0;
}