This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//author:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
struct DSU {
vector <int> par;
DSU(int n) {
par.resize(n);
iota(par.begin(), par.end(), 0ll);
}
bool same(int a, int b) {
return get(a) == get(b);
}
inline int get(int a) {
return par[a] = (par[a] == a ? a : get(par[a]));
}
void unite(int u, int v) {
par[get(u)] = get(v);
}
};
void solve() {
int n, m, q;
cin >> n >> m >> q;
DSU dsu(n +1);
for(int i = 1; i <= m; i++) {
for(int j = 1; j <= n; j++) {
int x;
cin >> x;
dsu.unite(j, x);
}
}
for(int i = 1; i <= q; i++) {
int a, b;
cin >> a >> b;
cout << (dsu.same(a, b) ? "DA" : "NE") << "\n";
}
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
while(t--)
solve();
return 0;
}
# | 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... |