#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
5584 KB |
Output is correct |
2 |
Correct |
80 ms |
4856 KB |
Output is correct |
3 |
Correct |
71 ms |
4552 KB |
Output is correct |
4 |
Correct |
88 ms |
5724 KB |
Output is correct |
5 |
Correct |
93 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
360 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
360 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
5584 KB |
Output is correct |
2 |
Correct |
80 ms |
4856 KB |
Output is correct |
3 |
Correct |
71 ms |
4552 KB |
Output is correct |
4 |
Correct |
88 ms |
5724 KB |
Output is correct |
5 |
Correct |
93 ms |
5580 KB |
Output is correct |
6 |
Correct |
2 ms |
360 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
144 ms |
9400 KB |
Output is correct |
27 |
Correct |
173 ms |
9376 KB |
Output is correct |
28 |
Correct |
115 ms |
7756 KB |
Output is correct |
29 |
Correct |
141 ms |
9012 KB |
Output is correct |
30 |
Correct |
147 ms |
8032 KB |
Output is correct |
31 |
Correct |
130 ms |
8004 KB |
Output is correct |
32 |
Correct |
144 ms |
9400 KB |
Output is correct |
33 |
Correct |
193 ms |
9324 KB |
Output is correct |
34 |
Correct |
143 ms |
9340 KB |
Output is correct |
35 |
Correct |
165 ms |
9388 KB |
Output is correct |