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;
const int N = 1000 + 10;
int n, par[N];
int root(int x)
{
if(par[x] == x) return x;
return par[x] = root(par[x]);
}
void merge(int x, int y)
{
x = root(x), y = root(y);
if(x == y) return;
par[x] = y;
}
int main()
{
int n, m, q;
cin >> n >> m >> q;
iota(par, par + n + 1, 0);
for(int i = 0; i < m ; i++)
{
for(int j = 1, pj; j <= n; j ++)
{
cin >> pj;
merge(j, pj);
}
}
while(q--)
{
int x, y;
cin >> x >> y;
cout << (root(x) == root(y) ? "DA" : "NE") << endl;
}
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... |