#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,m,q;
int root[1005];
int findroot(int x){
if(x!=root[x]){
root[x] = findroot(root[x]);
}
return root[x];
}
void domerge(int a, int b){
a = findroot(a);
b = findroot(b);
if(a==b){
return;
}
root[a] = b;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
for(int i=1;i<=n;i++){
root[i] = i;
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
int a;
cin >> a;
domerge(a,j);
}
}
for(int i=1;i<=q;i++){
int a,b;
cin >> a >> b;
if(findroot(a)==findroot(b)){
cout << "DA" << "\n";
}
else{
cout << "NE" << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
5704 KB |
Output is correct |
2 |
Correct |
75 ms |
4860 KB |
Output is correct |
3 |
Correct |
80 ms |
4616 KB |
Output is correct |
4 |
Correct |
84 ms |
5596 KB |
Output is correct |
5 |
Correct |
92 ms |
5568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
336 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 |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
352 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 |
87 ms |
5704 KB |
Output is correct |
2 |
Correct |
75 ms |
4860 KB |
Output is correct |
3 |
Correct |
80 ms |
4616 KB |
Output is correct |
4 |
Correct |
84 ms |
5596 KB |
Output is correct |
5 |
Correct |
92 ms |
5568 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 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 |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
336 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 |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
352 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 |
145 ms |
9420 KB |
Output is correct |
27 |
Correct |
157 ms |
9352 KB |
Output is correct |
28 |
Correct |
111 ms |
7716 KB |
Output is correct |
29 |
Correct |
143 ms |
9008 KB |
Output is correct |
30 |
Correct |
135 ms |
7960 KB |
Output is correct |
31 |
Correct |
129 ms |
8012 KB |
Output is correct |
32 |
Correct |
140 ms |
9420 KB |
Output is correct |
33 |
Correct |
154 ms |
9420 KB |
Output is correct |
34 |
Correct |
153 ms |
9404 KB |
Output is correct |
35 |
Correct |
151 ms |
9376 KB |
Output is correct |