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;
using ll = long long int;
const int maxn = 5e5 + 5;
const int oo = 1e9 + 7;
const ll inf = 1e18;
int n, m, q;
vector<int> adj[maxn];
int comp[maxn], cnt = 0;
void dfs(int u) {
comp[u] = cnt;
for (auto j : adj[u]) {
if (comp[j])
continue;
dfs(j);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
int u;
cin >> u;
adj[u].push_back(j);
}
}
for (int i = 1; i <= n; i++) {
if (!comp[i]) {
++cnt;
dfs(i);
}
}
while (q--) {
int u, v;
cin >> u >> v;
if (comp[u] == comp[v])
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... |