# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
579163 | Trisanu_Das | Kutije (COCI21_kutije) | C++17 | 0 ms | 0 KiB |
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;
int parent[1001];
int find(int u){
if(u = parent[u]) return u;
return parent[u] = find(parent[u]);
}
void join(int u, int v){
u = find(u); v = find(b);
if(a == b) return;
parent[b] = a;
}
int main(){
int n, m, q; cin >> n >> m >> q;
for(int i = 1; i < n + 1; i++) parent[i] = i;
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= n; j++)
{
int x; cin >> x;
if(find(x) != find(j)) join(x, j);
}
}
while(q--){
int a, b; cin >> a >> b;
if(find(a) == find(b)) cout << "DE\n"; else cout << "NE\n";
}
}