# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499543 | adam | Kutije (COCI21_kutije) | C++14 | 0 ms | 0 KiB |
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 m = 1005;
vector<int>g[m];
bool p[m];
int c[m];
void q(int v, int no) {
p[v] = 1;
c[v] = no;
for(auto u : g[v]) if(!p[u]) {
q(u, no);
}
}
void y() {
int n, m, q; cin >> n >> m >> q;
while(m--) {
for(int i=1; i<=n; ++i) {
int to; cin >> to;
g[i].push_back(to);
g[to].push_back(i);
}
}
int cur = 1;
for(int i=1; i<=n; ++i) if(!p[i]) {
DFS(i, cur);
++cur;
}
while(q--) {
int a, b; cin >> a >> b;
if(c[a]==c[b]) {
cout << "DA";
} else {
cout << "NE";
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
y();
return 0;
}