#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 |
1 |
Correct |
85 ms |
36948 KB |
Output is correct |
2 |
Correct |
71 ms |
36180 KB |
Output is correct |
3 |
Correct |
96 ms |
35932 KB |
Output is correct |
4 |
Correct |
84 ms |
36944 KB |
Output is correct |
5 |
Correct |
82 ms |
36920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
32088 KB |
Output is correct |
2 |
Correct |
8 ms |
32092 KB |
Output is correct |
3 |
Correct |
9 ms |
32092 KB |
Output is correct |
4 |
Correct |
8 ms |
32092 KB |
Output is correct |
5 |
Correct |
8 ms |
32088 KB |
Output is correct |
6 |
Correct |
7 ms |
32088 KB |
Output is correct |
7 |
Correct |
8 ms |
32092 KB |
Output is correct |
8 |
Correct |
8 ms |
31952 KB |
Output is correct |
9 |
Correct |
9 ms |
32108 KB |
Output is correct |
10 |
Correct |
9 ms |
32092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
32088 KB |
Output is correct |
2 |
Correct |
8 ms |
32092 KB |
Output is correct |
3 |
Correct |
9 ms |
32092 KB |
Output is correct |
4 |
Correct |
8 ms |
32092 KB |
Output is correct |
5 |
Correct |
8 ms |
32088 KB |
Output is correct |
6 |
Correct |
7 ms |
32088 KB |
Output is correct |
7 |
Correct |
8 ms |
32092 KB |
Output is correct |
8 |
Correct |
8 ms |
31952 KB |
Output is correct |
9 |
Correct |
9 ms |
32108 KB |
Output is correct |
10 |
Correct |
9 ms |
32092 KB |
Output is correct |
11 |
Correct |
8 ms |
32092 KB |
Output is correct |
12 |
Correct |
8 ms |
32092 KB |
Output is correct |
13 |
Correct |
8 ms |
32088 KB |
Output is correct |
14 |
Correct |
8 ms |
32084 KB |
Output is correct |
15 |
Correct |
8 ms |
32092 KB |
Output is correct |
16 |
Correct |
9 ms |
32256 KB |
Output is correct |
17 |
Correct |
9 ms |
32092 KB |
Output is correct |
18 |
Correct |
8 ms |
32092 KB |
Output is correct |
19 |
Correct |
8 ms |
32092 KB |
Output is correct |
20 |
Correct |
8 ms |
32160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
36948 KB |
Output is correct |
2 |
Correct |
71 ms |
36180 KB |
Output is correct |
3 |
Correct |
96 ms |
35932 KB |
Output is correct |
4 |
Correct |
84 ms |
36944 KB |
Output is correct |
5 |
Correct |
82 ms |
36920 KB |
Output is correct |
6 |
Correct |
9 ms |
32088 KB |
Output is correct |
7 |
Correct |
8 ms |
32092 KB |
Output is correct |
8 |
Correct |
9 ms |
32092 KB |
Output is correct |
9 |
Correct |
8 ms |
32092 KB |
Output is correct |
10 |
Correct |
8 ms |
32088 KB |
Output is correct |
11 |
Correct |
7 ms |
32088 KB |
Output is correct |
12 |
Correct |
8 ms |
32092 KB |
Output is correct |
13 |
Correct |
8 ms |
31952 KB |
Output is correct |
14 |
Correct |
9 ms |
32108 KB |
Output is correct |
15 |
Correct |
9 ms |
32092 KB |
Output is correct |
16 |
Correct |
8 ms |
32092 KB |
Output is correct |
17 |
Correct |
8 ms |
32092 KB |
Output is correct |
18 |
Correct |
8 ms |
32088 KB |
Output is correct |
19 |
Correct |
8 ms |
32084 KB |
Output is correct |
20 |
Correct |
8 ms |
32092 KB |
Output is correct |
21 |
Correct |
9 ms |
32256 KB |
Output is correct |
22 |
Correct |
9 ms |
32092 KB |
Output is correct |
23 |
Correct |
8 ms |
32092 KB |
Output is correct |
24 |
Correct |
8 ms |
32092 KB |
Output is correct |
25 |
Correct |
8 ms |
32160 KB |
Output is correct |
26 |
Correct |
154 ms |
66056 KB |
Output is correct |
27 |
Correct |
150 ms |
66076 KB |
Output is correct |
28 |
Correct |
124 ms |
61780 KB |
Output is correct |
29 |
Correct |
142 ms |
65276 KB |
Output is correct |
30 |
Correct |
131 ms |
61640 KB |
Output is correct |
31 |
Correct |
134 ms |
62292 KB |
Output is correct |
32 |
Correct |
148 ms |
65120 KB |
Output is correct |
33 |
Correct |
147 ms |
64720 KB |
Output is correct |
34 |
Correct |
164 ms |
64772 KB |
Output is correct |
35 |
Correct |
146 ms |
65724 KB |
Output is correct |