#include <bits/stdc++.h>
using namespace std;
# define pb push_back
# define int long long
int n, m, q;
const int N = 1100;
int parent[N];
int depth[N];
int a[N];
int find_set(int a){
if (parent[a] == a){
return a;
}
return parent[a] = find_set(parent[a]);
}
void merge_set(int a, int b){
a = find_set(a);
b = find_set(b);
if (a == b){
return;
}
if (depth[a] < depth[b]){
swap(a, b);
}
parent[b] = a;
if (depth[a] == depth[b]){
depth[a]++;
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for (int i= 0; i < N; i++){
parent[i] = i;
}
for (int i = 1; i <= m; i++){
for (int j = 1; j <= n; j++){
cin >> a[j];
merge_set(a[j], j);
}
}
while (q--){
int x, y;
cin >> x >> y;
if (find_set(x) == find_set(y)){
cout << "DA" << endl;
}
else{
cout << "NE" << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
536 ms |
5716 KB |
Output is correct |
2 |
Correct |
461 ms |
4944 KB |
Output is correct |
3 |
Correct |
468 ms |
4704 KB |
Output is correct |
4 |
Correct |
534 ms |
5712 KB |
Output is correct |
5 |
Correct |
535 ms |
5624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
500 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
536 ms |
5716 KB |
Output is correct |
2 |
Correct |
461 ms |
4944 KB |
Output is correct |
3 |
Correct |
468 ms |
4704 KB |
Output is correct |
4 |
Correct |
534 ms |
5712 KB |
Output is correct |
5 |
Correct |
535 ms |
5624 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
500 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
571 ms |
9428 KB |
Output is correct |
27 |
Correct |
570 ms |
9548 KB |
Output is correct |
28 |
Correct |
503 ms |
7764 KB |
Output is correct |
29 |
Correct |
598 ms |
9116 KB |
Output is correct |
30 |
Correct |
494 ms |
8196 KB |
Output is correct |
31 |
Correct |
494 ms |
8276 KB |
Output is correct |
32 |
Correct |
599 ms |
9340 KB |
Output is correct |
33 |
Correct |
571 ms |
9532 KB |
Output is correct |
34 |
Correct |
568 ms |
9460 KB |
Output is correct |
35 |
Correct |
647 ms |
9412 KB |
Output is correct |