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;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
vector<int> adg[n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
int a;
cin >> a;
a--;
adg[a].push_back(j);
}
}
bool reach[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
reach[i][j]=0;
}
}
for(int i=0; i<n; i++){
queue<int> que;
que.push(i);
reach[i][i]=true;
while(!que.empty()){
int cur = que.front();
que.pop();
for(auto u : adg[cur]){
if(!reach[i][u]){
reach[i][u]=true;
que.push(u);
}
}
}
}
// for(int i=0; i<n; i++){
// cout << i << ": ";
// for(auto u : adg[i]){
// cout << u;
// }
// cout << '\n';
// }
for(int query=0; query<q; query++){
int a, b;
cin >> a >> b;
a--;
b--;
if(reach[a][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... |