Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define bp __builtin_popcountll
  3. #define pb push_back
  4. #define in(s) freopen(s, "r", stdin);
  5. #define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
  6. freopen((string(s) + "." + end2).c_str(), "w", stdout);
  7. #define fi first
  8. #define se second
  9. #define bw(i, r, l) for (int i = r - 1; i >= l; i--)
  10. #define fw(i, l, r) for (int i = l; i < r; i++)
  11. #define fa(i, x) for (auto i: x)
  12. using namespace std;
  13. const int mod = 1e9 + 7, inf = 1061109567;
  14. const long long infll = 4557430888798830399;
  15. typedef long long ll;
  16. const int N = 305;
  17. int n, d[N][N], q;
  18. signed main() {
  19. #ifdef BLU
  20. in("blu.inp");
  21. #endif
  22. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  23. cin >> n;
  24. fw (i, 0, n) fw (j, 0, n) cin >> d[i][j];
  25. cin >> q;
  26. while (q--) {
  27. int a, b, c;
  28. cin >> a >> b >> c;
  29. a--, b--;
  30. ll ans = 0;
  31. fw (i, 0, n) fw (j, 0, n) {
  32. d[i][j] = min(d[i][j], d[i][a] + d[b][j] + c);
  33. d[i][j] = min(d[i][j], d[i][b] + d[a][j] + c);
  34. ans += d[i][j];
  35. }
  36. cout << ans / 2 << " ";
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement