Submission #1102456

#TimeUsernameProblemLanguageResultExecution timeMemory
1102456yavuzskarahanKutije (COCI21_kutije)C++14
70 / 70
781 ms1944 KiB
// In the name of God, the Most Gracious, the Most Merciful.
// iflbot(); - @yavuzskarahan
 
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define FOR(i, L, R) for(int i = (L); i <= (R); i++)
#define pb push_back
 
short n, m, a, b;
int q;
short parent[1002];
 
inline short find(short a){
    if (a==parent[a]) return a;
    else return parent[a] = find(parent[a]);
}
 
inline void unite(short a, short b){
    a = find(a);
    b = find(b);
    parent[b] = a;
    return;
}
 
inline int solve(){
 
    cin >> n >> m >> q;
 
    for(short i = 1; i <= n; i++) parent[i] = i;
 
    for(short i = 1; i <= m; i++){
        for(short j = 1; j <= n; j++){
            cin >> a;
            unite(j,a);
        }
    }
 
    while(q--){
        cin >> a >> b;
        if (find(a) == find(b)) cout << "DA" << endl;
        else cout << "NE" << endl;
    }
 
    return 0;
 
}
 
int main() {
 
    fast;
    solve();
    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...