This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, M, Q;
vector<int> v[1010];
struct dsu {
int par[1010];
void init() {
iota(par, par + 1005, 0);
}
int p(int pos) {
return par[pos] = (pos == par[pos] ? pos : p(par[pos]));
}
void unite(int a, int b) {
a = p(a);
b = p(b);
if (a == b) return;
par[a] = b;
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> Q;
dsu d;
d.init();
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
int x;
cin >> x;
x--;
d.unite(x, j);
}
}
for (int i = 0; i < Q; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
if (d.p(a) == d.p(b))
cout << "DA\n";
else
cout << "NE\n";
}
}
# | 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... |