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;
const int MX = 1005;
vector<int>g[MX];
bool vis[MX];
int comp[MX];
void DFS(int v, int no) {
vis[v] = 1;
comp[v] = no;
for(auto u : g[v]) if(!vis[u]) {
DFS(u, no);
}
}
void PlayGround() {
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(!vis[i]) {
DFS(i, cur);
++cur;
}
while(q--) {
int a, b; cin >> a >> b;
if(comp[a]==comp[b]) {
cout << "DA\n";
} else {
cout << "NE\n";
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
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... |