이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |