Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define bp __builtin_popcountll
- #define pb push_back
- #define in(s) freopen(s, "r", stdin);
- #define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
- freopen((string(s) + "." + end2).c_str(), "w", stdout);
- #define fi first
- #define se second
- #define bw(i, r, l) for (int i = r - 1; i >= l; i--)
- #define fw(i, l, r) for (int i = l; i < r; i++)
- #define fa(i, x) for (auto i: x)
- using namespace std;
- const int mod = 1e9 + 7, inf = 1061109567;
- const long long infll = 4557430888798830399;
- typedef long long ll;
- const int N = 305;
- int n, d[N][N], q;
- signed main() {
- #ifdef BLU
- in("blu.inp");
- #endif
- ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- cin >> n;
- fw (i, 0, n) fw (j, 0, n) cin >> d[i][j];
- cin >> q;
- while (q--) {
- int a, b, c;
- cin >> a >> b >> c;
- a--, b--;
- ll ans = 0;
- fw (i, 0, n) fw (j, 0, n) {
- d[i][j] = min(d[i][j], d[i][a] + d[b][j] + c);
- d[i][j] = min(d[i][j], d[i][b] + d[a][j] + c);
- ans += d[i][j];
- }
- cout << ans / 2 << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement