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], 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... |