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;
#define ll long long
#define ar array
const int mxN=1000;
int n, m, q, cmp[mxN], c;
bool adj[mxN][mxN];
void dfs(int u) {
cmp[u]=c;
for (int v=0; v<n; ++v)
if (adj[u][v]&&!cmp[v])
dfs(v);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int i=0; i<m; ++i)
for (int j=0; j<n; ++j) {
int k;
cin >> k, --k;
adj[j][k]=adj[k][j]=1;
}
for (int i=0; i<n; ++i)
if (!cmp[i])
++c, dfs(i);
while(q--) {
int u, v;
cin >> u >> v, --u, --v;
cout << (cmp[u]==cmp[v]?"DA":"NE") << "\n";
}
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... |