#include <bits/stdc++.h>
using namespace std;
//~ #define int long long
#define fr first
#define sc second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(),x.end()
#define sp << " " <<
#define inf 1e18+1
#define N 1000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tuple<int,int,int> tiii;
typedef pair<int,int> pii;
int dsu[N+5];
int find(int x){
if(dsu[x]<0)
return x;
return dsu[x]=find(dsu[x]);
}
void comb(int x,int y){
x=find(x);
y=find(y);
if(x==y)
return;
dsu[x]=y;
}
void solve(){
memset(dsu,-1,sizeof(dsu));
int n,m,q;
cin >> n >> m >> q;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
int x;
cin >> x;
comb(x,j+1);
}
}
while(q--){
int x,y;
cin >> x >> y;
x=find(x);
y=find(y);
if(x==y) cout << "DA" << endl;
else cout << "NE" << endl;
}
}
int32_t main(){
//~ freopen("a.txt","r",stdin);
fast;
int test=1;
//~ cin >> test;
while(test--) solve();
}
# | 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... |