This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
const int N = 1005;
int p[N], sz[N];
int findp(int u) {
return p[u] = (p[u] == u ? u : findp(p[u]));
}
void merge(int u, int v) {
u = findp(u), v = findp(v);
if (u == v)return;
if (sz[u] < sz[v])swap(u, v);
sz[u] += sz[v];
p[v] = u;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
p[i] = i;
sz[i] = 1;
}
while (m--) {
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
merge(i, x);
}
}
while (q--) {
int a, b;
cin >> a >> b;
cout << (findp(a) == findp(b) ? "DA\n" : "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... |