Submission #798020

#TimeUsernameProblemLanguageResultExecution timeMemory
798020tlnk07Kutije (COCI21_kutije)C++17
25 / 70
724 ms6580 KiB
#include<bits/stdc++.h>
using namespace std;

long long n, m, q, a[1001][1001], x, y;
bool check[1001][1001];

void dfs1(int x, int y)
{
	if(check[x][y])	return;
	check[x][y] = true;
	dfs1(x, a[1][y]);
}

int main()
{
	cin >> n >> m >> q;
	if(m == 1)
	{
		for(int i = 1; i <= n; ++i)	cin >> a[1][i];
		for(int i = 1; i <= n; ++i)	dfs1(i, i);
		while(q--)
		{
			cin >> x >> y;
			if(check[x][y])	cout << "DA\n";
			else	cout << "NE\n";
		}
	}
	else
	{
		for(int i = 1; i <= m; ++i)	for(int j = 1; j <= n; ++j)	cin >> a[i][j];
		for(int i = 1; i <= m; ++i)	for(int j = 1; j <= m; ++j)	for(int l = 1; l <= n; ++l)	check[l][l] = check[l][a[i][l]] = check[l][a[j][l]] = check[l][a[i][a[j][l]]] = check[l][a[j][a[i][l]]] = true;
		while(q--)
		{
			cin >> x >> y;
			if(check[x][y])	cout << "DA\n";
			else	cout << "NE\n";
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...