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;
vector <long long> graph[1000005];
long long tplt[1000005], id = 1;
void dfs(long long u)
{
for (auto v:graph[u])
{
if (tplt[v] != -1) continue;
tplt[v] = id;
dfs(v);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, q;
cin >> n >> m >> q;
long long p[m + 1][n + 1];
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> p[i][j];
graph[j].push_back(p[i][j]);
graph[p[i][j]].push_back(j);
}
}
memset(tplt, -1, sizeof tplt);
for (int i = 1; i <= n; i++)
{
if (tplt[i] == -1)
{
id++;
dfs(i);
}
}
for (int i = 1; i <= q; i++)
{
long long a, b;
cin >> a >> b;
if (tplt[a] == tplt[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... |