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;
#define ll long long
int const N=2e5+5;
int const mod=1e9+7;
vector<int> adj[N];
int com[N],c=0;
void dfs(int node){
com[node]=c;
for(int i:adj[node])
if(com[i]==0)
dfs(i);
}
int main(){
int n,m,q;
cin>>n>>m>>q;
while(m--){
for(int i=1;i<=n;i++){
int p;
cin>>p;
adj[p].push_back(i);
adj[i].push_back(p);
}
}
for (int i = 1; i <=n; ++i)
if(com[i]==0){
c++;
dfs(i);
}
while(q--){
int u,v;
cin>>u>>v;
if(com[u]==com[v])
cout<<"DA"<<endl;
else
cout<<"NE"<<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... |