#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
int n, m, q, a, b, arr[N];
struct DSU{
int par[N], stsize[N];
DSU(){
for(int i = 1; i < N; i++) par[i] = i, stsize[i] = 1;
}
int setfind(int a){
if(par[a] == a) return a;
else return par[a] = setfind(par[a]);
}
void setunion(int a, int b){
a = setfind(a), b = setfind(b);
if(a != b){
if(stsize[b] > stsize[a]) swap(a, b);
par[b] = par[a];
stsize[a] += stsize[b];
}
}
};
DSU dsu;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> m >> q;
for(int i = 1; i <= m; i++){
for(int i = 1; i <= n; i++) cin >> arr[i];
for(int i = 1; i <= n; i++) dsu.setunion(i, arr[i]);
}
while(q--){
cin >> a >> b;
if(dsu.setfind(a) == dsu.setfind(b)) cout << "DA\n";
else cout << "NE\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1864 KB |
Output is correct |
2 |
Correct |
43 ms |
1608 KB |
Output is correct |
3 |
Correct |
41 ms |
1640 KB |
Output is correct |
4 |
Correct |
47 ms |
1864 KB |
Output is correct |
5 |
Correct |
53 ms |
1928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1864 KB |
Output is correct |
2 |
Correct |
43 ms |
1608 KB |
Output is correct |
3 |
Correct |
41 ms |
1640 KB |
Output is correct |
4 |
Correct |
47 ms |
1864 KB |
Output is correct |
5 |
Correct |
53 ms |
1928 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
91 ms |
1736 KB |
Output is correct |
27 |
Correct |
105 ms |
1856 KB |
Output is correct |
28 |
Correct |
77 ms |
1612 KB |
Output is correct |
29 |
Correct |
92 ms |
1864 KB |
Output is correct |
30 |
Correct |
115 ms |
1480 KB |
Output is correct |
31 |
Correct |
79 ms |
1612 KB |
Output is correct |
32 |
Correct |
97 ms |
1748 KB |
Output is correct |
33 |
Correct |
97 ms |
1864 KB |
Output is correct |
34 |
Correct |
93 ms |
1864 KB |
Output is correct |
35 |
Correct |
117 ms |
1856 KB |
Output is correct |