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;
#define lg long long
const lg N = 2e5+5;
lg par[N], compSize[N];
lg get(lg src)
{
if(par[src] == src) return src;
return par[src] = get(par[src]);
}
void join(lg u, lg v)
{
u = get(u);
v = get(v);
if(u == v) return;
if(compSize[u] > compSize[v]) swap(u, v);
par[u] = v;
compSize[v] += compSize[u];
return;
}
int main()
{
lg n, m, q;
cin >> n >> m >> q;
for(int i = 1; i <= n; i++) par[i] = i, compSize[i] = 1;
for(int i = 0; i < m; i++)
{
for(int j = 1; j <= n; j++)
{
lg x;
cin >> x;
join(x, j);
}
}
while(q--)
{
lg a, b;
cin >> a >> b;
cout << (get(a) == get(b) ? "DA" : "NE") << '\n';
}
}
/*
-2 -1 -2 -1 1 -2 -2 -2 -1 -2 -1 -2 -1 -1 -1 -1
-2 -1 -2 -1 -2 -2 -2 -2 -2 -2 -2 -2 0 -2 -2 -2
-2 -2 -2 -2 -1 -2 -1 -2 0 -2 -2 -2 -1 -2 -1 -2
2
*/
# | 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... |