This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of God, the Most Gracious, the Most Merciful.
// iflbot(); - @yavuzskarahan
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
short n, m, a, b;
int q;
short parent[1002];
inline short find(short a){
if (a==parent[a]) return a;
else return parent[a] = find(parent[a]);
}
inline void unite(short a, short b){
a = find(a);
b = find(b);
parent[b] = a;
return;
}
inline int solve(){
cin >> n >> m >> q;
for(short i = 1; i <= n; i++) parent[i] = i;
for(short i = 1; i <= m; i++){
for(short j = 1; j <= n; j++){
cin >> a;
unite(j,a);
}
}
while(q--){
cin >> a >> b;
if (find(a) == find(b)) cout << "DA" << endl;
else cout << "NE" << endl;
}
return 0;
}
int main() {
fast;
solve();
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... |