#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> fw_correct(vector<vector<int>> W) {
int n = (int)W.size();
for (int b = 0; b < n; ++b)
for (int a = 0; a < n; ++a)
for (int c = 0; c < n; ++c)
W[a][c] = min(W[a][c], W[a][b]+W[b][c]);
return W;
}
vector<vector<int>> fw_wrong(vector<vector<int>> W) {
int n = (int)W.size();
for (int a = 0; a < n; ++a)
for (int c = 0; c < n; ++c)
for (int b = 0; b < n; ++b)
W[a][c] = min(W[a][c], W[a][b]+W[b][c]);
return W;
}
void print(const vector<vector<int>> &W) {
int n = (int)W.size();
for (int r = 0; r < n; ++r) {
cout << '\t';
for (int c = 0; c < n; ++c)
cout << W[r][c] << "\t\n"[c+1==n];
}
}
int main() {
vector<vector<int>> W(4, vector<int>(4, 99));
W[0][2] = W[2][0] = 1;
W[2][3] = W[3][2] = 1;
W[3][1] = W[1][3] = 1;
cout << "Correct:" << endl;
print(fw_correct(W));
cout << "Wrong:" << endl;
print(fw_wrong(W));
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2ZWN0b3I8dmVjdG9yPGludD4+IGZ3X2NvcnJlY3QodmVjdG9yPHZlY3RvcjxpbnQ+PiBXKSB7CglpbnQgbiA9IChpbnQpVy5zaXplKCk7Cglmb3IgKGludCBiID0gMDsgYiA8IG47ICsrYikKCQlmb3IgKGludCBhID0gMDsgYSA8IG47ICsrYSkKCQkJZm9yIChpbnQgYyA9IDA7IGMgPCBuOyArK2MpCgkJCQlXW2FdW2NdID0gbWluKFdbYV1bY10sIFdbYV1bYl0rV1tiXVtjXSk7CglyZXR1cm4gVzsKfQoKdmVjdG9yPHZlY3RvcjxpbnQ+PiBmd193cm9uZyh2ZWN0b3I8dmVjdG9yPGludD4+IFcpIHsKCWludCBuID0gKGludClXLnNpemUoKTsKCWZvciAoaW50IGEgPSAwOyBhIDwgbjsgKythKQoJCWZvciAoaW50IGMgPSAwOyBjIDwgbjsg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