Submission #1022177

#TimeUsernameProblemLanguageResultExecution timeMemory
1022177vjudge1Kutije (COCI21_kutije)C++17
70 / 70
898 ms2132 KiB
#include<bits/stdc++.h>

using namespace std;

const int N = 1000 + 10;
int n, par[N];

int root(int x)
{
  if(par[x] == x) return x;
  return par[x] = root(par[x]);
}
void merge(int x, int y)
{
  x = root(x), y = root(y);
  if(x == y) return;
  par[x] = y;
}

int main()
{
  int n, m, q;
  cin >> n >> m >> q;

  iota(par, par + n + 1, 0);

  for(int i = 0; i < m ; i++)
    {
      for(int j = 1, pj; j <= n; j ++)
	{
	  cin >> pj;
	  merge(j, pj);
	}
    }

  while(q--)
    {
      int x, y;
      cin >> x >> y;
      cout << (root(x) == root(y) ? "DA" : "NE") << endl;
    }
  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...