fork(2) 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][4]=a[4][3]=a[3][2]=1;
  12. for(i=1;i<=n;i++)
  13. for(k=1;k<=n;k++)
  14. for(j=1;j<=n;j++)
  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.02s 2680KB
stdin
Standard input is empty
stdout
0 9 2 1
9 0 9 9
9 1 0 9
9 2 1 0