이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
# define pb push_back
# define int long long
int n, m, q;
const int N = 1100;
int parent[N];
int depth[N];
int a[N];
int find_set(int a){
if (parent[a] == a){
return a;
}
return parent[a] = find_set(parent[a]);
}
void merge_set(int a, int b){
a = find_set(a);
b = find_set(b);
if (a == b){
return;
}
if (depth[a] < depth[b]){
swap(a, b);
}
parent[b] = a;
if (depth[a] == depth[b]){
depth[a]++;
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for (int i= 0; i < N; i++){
parent[i] = i;
}
for (int i = 1; i <= m; i++){
for (int j = 1; j <= n; j++){
cin >> a[j];
merge_set(a[j], j);
}
}
while (q--){
int x, y;
cin >> x >> y;
if (find_set(x) == find_set(y)){
cout << "DA" << endl;
}
else{
cout << "NE" << endl;
}
}
}
# | 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... |