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;
using ll = long long;
void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,m,q;
cin >> n >> m >> q;
vector <vector<int>>arr(n,vector<int>(m));
for(int i = 0;i < m;i++){
for(int j = 0;j < n;j++){
cin >> arr[j][i];
arr[j][i]--;
}
}
vector <int> res(n,-1);
for(int i = 0;i < n;i++){
if(res[i] != -1)continue;
queue <int> qu;
qu.push(i);
while(!qu.empty()){
int j = qu.front();
qu.pop();
if(res[j] == i)continue;
res[j]=i;
for(int k : arr[j])qu.push(k);
}
}
while(q--){
int a,b;
cin >> a >> b;
a--;
b--;
if(res[a] == res[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... |