| Task: | Shallow waters |
| Sender: | ind1f |
| Submission time: | 2025-10-22 17:28:53 +0300 |
| Language: | C++ (C++17) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'void bfs(int)':
input/code.cpp:46:17: error: request for member 'first' in 'x', which is of non-class type 'int'
46 | int v = x.first, w = x.second;
| ^~~~~
input/code.cpp:48:20: error: 'w' was not declared in this scope
48 | d[v] = min(w, d[u]);
| ^
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33,
from /usr/include/c++/11/bits/allocator.h:46,
from /usr/include/c++/11/string:41,
from /usr/include/c++/11/bits/locale_classes.h:40,
from /usr/include/c++/11/bits/ios_base.h:41,
from /usr/include/c++/11/ios:42,
from /usr/include/c++/11/istream:38,
from /usr/include/c++/11/sstream:38,
from /usr/include/c++/11/complex:45,
from /usr/include/c++/11/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/1...Code
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 5;
struct dsu {
int lab[N];
dsu() {
memset(lab, -1, sizeof(lab));
}
int find(int u) {
return lab[u] < 0 ? u : lab[u] = find(lab[u]);
}
bool merge(int u, int v) {
if ((u = find(u)) == (v = find(v))) {
return false;
}
if (lab[u] > lab[v]) {
swap(u, v);
}
lab[u] += lab[v];
lab[v] = u;
return true;
}
};
int n, q;
vector<array<int, 3> > e;
vector<int> adj[N];
dsu g;
int d[N];
void bfs(int src) {
memset(d, -1, sizeof(d));
queue<int> q;
q.push(src);
d[src] = 0x3f3f3f3f;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto x : adj[u]) {
int v = x.first, w = x.second;
if (d[v] == -1) {
d[v] = min(w, d[u]);
q.push(v);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int a;
cin >> a;
e.emplace_back(array<int, 3>{-a, i, j});
}
}
sort(e.begin(), e.end());
for (auto x : e) {
if (g.merge(x[1], x[2])) {
adj[x[1]].emplace_back(x[2], -x[0]);
adj[x[2]].emplace_back(x[1], -x[0]);
}
}
while (q--) {
int x, y;
cin >> x >> y;
bfs(x);
cout << d[y] << '\n';
}
return 0;
}
