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 MAXN 1020
#define INF 999999999
#define ll long long
#define F first
#define S second
#define endl "\n"
int n, m, q, lista[MAXN][MAXN];
bool foi[MAXN];
void dfs(int x){
for(int i = 1; i < MAXN; i++){
if(lista[x][i] == 1 && !foi[i]){
foi[i] = true;
dfs(i);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> q;
for(int i = 0; i < m; i++){
for(int j = 1; j <= n; j++){
int x;
cin >> x;
lista[j][x] = 1;
}
}
for(int i = 0; i < q; i++){
int a, b;
for(int j = 0; j < MAXN; j++) foi[j] = false;
cin >> a >> b;
foi[a] = true;
dfs(a);
if(foi[b] || a == b) cout << "DA\n";
else cout << "NE\n";
}
}
# | 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... |