Submission #746321

#TimeUsernameProblemLanguageResultExecution timeMemory
746321TrunktyKutije (COCI21_kutije)C++14
70 / 70
157 ms9420 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,m,q;
int root[1005];

int findroot(int x){
    if(x!=root[x]){
        root[x] = findroot(root[x]);
    }
    return root[x];
}

void domerge(int a, int b){
    a = findroot(a);
    b = findroot(b);
    if(a==b){
        return;
    }
    root[a] = b;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        root[i] = i;
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            int a;
            cin >> a;
            domerge(a,j);
        }
    }
    for(int i=1;i<=q;i++){
        int a,b;
        cin >> a >> b;
        if(findroot(a)==findroot(b)){
            cout << "DA" << "\n";
        }
        else{
            cout << "NE" << "\n";
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...