제출 #588422

#제출 시각아이디문제언어결과실행 시간메모리
588422MilosMilutinovicKutije (COCI21_kutije)C++14
70 / 70
161 ms9464 KiB
/**
 *    author:  wxhtzdy
 *    created: 03.07.2022 11:16:52
**/
#include <bits/stdc++.h>

using namespace std;

class dsu {
  public:
  vector<int> p;
  int n;
  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }
  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }
  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, m, q;
  cin >> n >> m >> q;
  dsu d(n);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      cin >> x;
      --x;
      d.unite(j, x);
    }
  }
  while (q--) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    cout << (d.get(a) == d.get(b) ? "DA" : "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...