# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
899593 | duckindog | Kutije (COCI21_kutije) | C++14 | 125 ms | 9556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, m, q;
int par[N];
int root(int u) {
return (par[u] < 0 ? u : par[u] = root(par[u]));
}
void add(int u, int v) {
u = root(u); v = root(v);
if (u == v) return;
if (par[u] >= par[v]) swap(u, v);
par[u] += par[v];
par[v] = u;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
memset(par, -1, sizeof par);
cin >> n >> m >> q;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
int p; cin >> p;
add(j, p);
}
}
while(q--) {
int x, y; cin >> x >> y;
cout << (root(x) == root(y) ? "DA" : "NE") << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |