이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |