#include <bits/stdc++.h>
using namespace std;
long long int arr[1000010];
vector<long long int>adj[1000010];
vector<pair<long long int, long long int>>a_b;
bool vis[1000010];
long long int component[1010];
vector<string>str;
void dfs(long long int s, long long int j){
component[s]=j;
vis[s]=true;
for(auto x:adj[s]){
if(!vis[x]){
dfs(x, j);
}
}
}
int main(){
long long int n, m, q, i, j;
cin>>n>>m>>q;
for(j=0; j<m; j++){
for(i=1; i<=n; i++){
cin>>arr[i];
adj[i].push_back(arr[i]);
adj[arr[i]].push_back(i);
}
}
long long int a, b;
for(i=0; i<q; i++){
cin>>a>>b;
a_b.push_back({a, b});
}
for(i=1; i<=n; i++){
if(!vis[i]){
j++;
dfs(i, j);
}
}
for(i=0; i<q; i++){
a=a_b[i].first;
b=a_b[i].second;
if(component[b]==component[a]){
str.push_back("DA");
}
else{
str.push_back("NE");
}
}
for(i=0; i<q; i++){
cout<<str[i]<<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... |