#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 |
1 |
Correct |
688 ms |
6548 KB |
Output is correct |
2 |
Correct |
578 ms |
5788 KB |
Output is correct |
3 |
Correct |
556 ms |
5476 KB |
Output is correct |
4 |
Correct |
681 ms |
6584 KB |
Output is correct |
5 |
Correct |
684 ms |
6564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
852 KB |
Output is correct |
2 |
Correct |
5 ms |
924 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Correct |
4 ms |
800 KB |
Output is correct |
5 |
Correct |
4 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
852 KB |
Output is correct |
2 |
Correct |
5 ms |
924 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Correct |
4 ms |
800 KB |
Output is correct |
5 |
Correct |
4 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
4 ms |
792 KB |
Output is correct |
13 |
Correct |
5 ms |
832 KB |
Output is correct |
14 |
Correct |
4 ms |
852 KB |
Output is correct |
15 |
Correct |
4 ms |
832 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
4 ms |
852 KB |
Output is correct |
18 |
Correct |
4 ms |
852 KB |
Output is correct |
19 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
688 ms |
6548 KB |
Output is correct |
2 |
Correct |
578 ms |
5788 KB |
Output is correct |
3 |
Correct |
556 ms |
5476 KB |
Output is correct |
4 |
Correct |
681 ms |
6584 KB |
Output is correct |
5 |
Correct |
684 ms |
6564 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
5 ms |
924 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
800 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
4 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
852 KB |
Output is correct |
15 |
Correct |
4 ms |
852 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
4 ms |
792 KB |
Output is correct |
18 |
Correct |
5 ms |
832 KB |
Output is correct |
19 |
Correct |
4 ms |
852 KB |
Output is correct |
20 |
Correct |
4 ms |
832 KB |
Output is correct |
21 |
Correct |
4 ms |
852 KB |
Output is correct |
22 |
Correct |
4 ms |
852 KB |
Output is correct |
23 |
Correct |
4 ms |
852 KB |
Output is correct |
24 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |