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;
typedef long long ll;
#define ssize(a) ((int)(a.size()))
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>>pol(n);
for(int i = 0; i < m; ++i)
{
for(int j = 0; j < n; ++j)
{
int pi;
cin >> pi;
--pi;
pol[j].push_back(pi);
}
}
vector<vector<bool>>jest_pol(n, vector<bool>(n));
for(int i = 0; i < n; ++i)
{
queue<int>kol;
kol.push(i);
jest_pol[i][i] = 1;
while(!kol.empty())
{
int t = kol.front();
kol.pop();
for(auto j: pol[t])
if(jest_pol[i][j] == 0)
{
jest_pol[i][j] = 1;
kol.push(j);
}
}
}
while(q)
{
--q;
int a, b;
cin >> a >> b;
--a;
--b;
if(jest_pol[a][b])
cout << "DA\n";
else
cout << "NE\n";
}
return 0;
}
# | 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... |