This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long n, m, q, a[1001][1001], pos1, pos2;
bool ck[1001][1001];
void check(int pos1, int pos2)
{
if(ck[pos1][pos2])
{
return;
}
ck[pos1][pos2] = true;
check(pos1, a[1][pos2]);
}
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)
{
check(i, i);
}
while(q--)
{
cin >> pos1 >> pos2;
if(ck[pos1][pos2])
{
cout << "DA" << endl;
}
else
{
cout << "NE" << endl;
}
}
}
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)
{
ck[l][l] = true;
ck[l][a[i][l]] = true;
ck[l][a[j][l]] = true;
ck[l][a[i][a[j][l]]] = true;
ck[l][a[j][a[i][l]]] = true;
}
}
}
while(q--)
{
cin >> pos1 >> pos2;
if(ck[pos1][pos2])
{
cout << "DA" << endl;
}
else
{
cout << "NE" << endl;
}
}
}
}
# | 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... |