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;
typedef long long ll;
#define int ll
int n,m,q;
int root[1005];
int findroot(int x){
if(x!=root[x]){
root[x] = findroot(root[x]);
}
return root[x];
}
void domerge(int a, int b){
a = findroot(a);
b = findroot(b);
if(a==b){
return;
}
root[a] = b;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
for(int i=1;i<=n;i++){
root[i] = i;
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
int a;
cin >> a;
domerge(a,j);
}
}
for(int i=1;i<=q;i++){
int a,b;
cin >> a >> b;
if(findroot(a)==findroot(b)){
cout << "DA" << "\n";
}
else{
cout << "NE" << "\n";
}
}
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... |