이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |