fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int T,n,r,x,y;
  4. int a[1000][1000];
  5. int main()
  6. {
  7. cin>>T;
  8. for (int l=1; l<=T; l++) {
  9. cin>>n;
  10.  
  11. for (int j=1; j<=n; j++) {
  12. for(int k = 1; k <= n; k++) {
  13. int cost;
  14. cin >> cost;
  15. a[j][k] = cost;
  16. }
  17.  
  18. }
  19.  
  20. for (int i=1; i<=n; i++) {
  21. for (int j=1; j<=n; j++) {
  22. for (int k=1; k<=n; k++) {
  23. if (a[j][k]>(a[j][i]+a[i][k])) {
  24. a[j][k]=a[j][i]+a[i][k];
  25. //a[k][j]=a[j][i]+a[i][k];
  26. }
  27. }
  28. }
  29. }
  30. cin >> r;
  31. int s=0;
  32. for (int i=1; i<=r; i++) {
  33. cin>>x>>y;
  34. s+=a[x][y];
  35. }
  36. cout<<"Case #"<<l<<": "<<s;
  37. if (l!=T){
  38. cout<<'\n';
  39. }
  40. }
  41. }
  42.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty