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 sp << " " <<
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 1e3+1;
vi dad(N);
int find(int x) {
if (x == dad[x]) return x;
return dad[x] = find(dad[x]);
}
void unite(int x,int y) {
dad[find(x)] = find(y);
}
void solve() {
int n,m,q;
cin >> n >> m >> q;
for (int i=1;i<=n;i++) dad[i] = i;
for (int i=1;i<=m;i++) {
vi a(n+1);
for (int j=1;j<=n;j++) cin >> a[j];
for (int j=1;j<=n;j++) {
if(j!=a[j]){
unite(j,a[j]);
}
}
}
while (q--) {
int a,b;
cin >> a >> b;
cout << ((find(a) == find(b))?"DA\n":"NE\n");
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |