Submission #1308339

#TimeUsernameProblemLanguageResultExecution timeMemory
1308339guardianecKutije (COCI21_kutije)C++20
70 / 70
422 ms4560 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

vector<ll> parent;

ll find(ll x){
    if (parent[x]==x) return x;
    return parent[x] = find(parent[x]);
}

void unite(ll x, ll y){
    ll rx = find(x);
    ll ry = find(y);
    if (rx!=ry) {
        parent[rx] = ry;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n,m,q;
    cin >> n >> m >> q;
    parent.resize(n+1);
    iota(parent.begin(), parent.end(), 0);
    for (int i=0; i<m; i++){
        for (int j=1; j<=n; j++){
            ll val;
            cin >> val;
            unite(val, j);
        }
    }

    while(q--){
        ll a,b;
        cin >> a >> b;
        if (find(a) == find(b)){
            cout << "DA" << endl;
        } else cout << "NE" << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...