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;
constexpr int NMAX = 1005;
int N, M, Q;
vector <int> G[NMAX];
int comp[NMAX];
int nr;
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> Q;
for (int i = 1; i <= M; ++ i ) {
for (int j = 1; j <= N; ++ j ) {
int x;
cin >> x;
G[j].push_back(x);
G[x].push_back(j);
}
}
}
void Dfs (int nod) {
comp[nod] = nr;
for (auto it : G[nod]) {
if (comp[it] != 0) continue;
Dfs(it);
}
}
void Precompute () {
for (int i = 1; i <= N; ++ i ) {
if (comp[i] == 0) {
++ nr;
Dfs(i);
}
}
}
void Solve () {
for (int i = 1; i <= Q; ++ i ) {
int x, y;
cin >> x >> y;
cout << (comp[x] == comp[y] ? "DA\n" : "NE\n");
}
}
int main () {
Read();
Precompute();
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... |