fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. int a[5][5];
  7. int n=4,i,j,k;
  8. for(i=1;i<=n;i++)
  9. for(j=1;j<=n;j++)
  10. a[i][j] = i==j ? 0 : 9;
  11. a[1][3]=a[3][4]=a[4][2]=1;
  12. for(j=1;j<=n;j++)
  13. for(k=1;k<=n;k++)
  14. for(i=1;i<=n;i++)
  15. a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
  16. for(i=1;i<=n;i++)
  17. for(j=1;j<=n;j++)
  18. printf("%d%c",a[i][j],j<n?' ':'\n');
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
0 9 1 2
9 0 9 9
9 2 0 1
9 1 9 0