이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
struct node{
long long parent;
long long rank;
};
node v[200005];
long long find(long long u){
if(u != v[u].parent){
v[u].parent = find(v[u].parent);
}
return v[u].parent;
}
void merge(long long x, long long y){
long long px = find(x);
long long py = find(y);
if(v[px].rank > v[py].rank){
v[py].parent = px;
}else{
v[px].parent = py;
}
if(v[px].rank == v[py].rank){
v[py].rank++;
}
}
int main(){
cin >> n >> m >> q;
for (int i = 1; i <= n; ++i)
{
v[i].parent = i;
v[i].rank = 0;
}
for (int i = 1; i <= m; ++i)
{
for (int j = 1; j <= n; ++j)
{
int t;
cin >> t;
merge(t, j);
}
}
while(q--){
int l, r;
cin >> l >> r;
if(find(l) == find(r)){
cout << "DA\n";
}
else{
cout << "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... |