#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
struct dsu{
vector<int> arr;
void init(int s){
arr.resize(s);
for(int i=0;i<s;i++){
arr[i]=i;
}
}
int query(int a){
if(arr[a]==a) return arr[a];
arr[a] = query(arr[a]);
return arr[a];
}
void join(int a,int b){
a = query(a);
b= query(b);
arr[a]=b;
return ;
}
} D;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m,q;cin>>n>>m>>q;
D.init(n);
for(int i=0;i<m;i++){
for(int i=0;i<n;i++){
int b;cin>>b;
b--;
D.join(i,b);
}
}
while(q--){
int a,b;cin>>a>>b;
a--;b--;
if(D.query(a)==D.query(b)) cout<<"DA\n";
else cout<<"NE\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
5524 KB |
Output is correct |
2 |
Correct |
66 ms |
4920 KB |
Output is correct |
3 |
Correct |
65 ms |
4560 KB |
Output is correct |
4 |
Correct |
79 ms |
5532 KB |
Output is correct |
5 |
Correct |
80 ms |
5548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 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 |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 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 |
2 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
5524 KB |
Output is correct |
2 |
Correct |
66 ms |
4920 KB |
Output is correct |
3 |
Correct |
65 ms |
4560 KB |
Output is correct |
4 |
Correct |
79 ms |
5532 KB |
Output is correct |
5 |
Correct |
80 ms |
5548 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 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 |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 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 |
2 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
149 ms |
9508 KB |
Output is correct |
27 |
Correct |
148 ms |
9380 KB |
Output is correct |
28 |
Correct |
112 ms |
7756 KB |
Output is correct |
29 |
Correct |
142 ms |
8988 KB |
Output is correct |
30 |
Correct |
122 ms |
7976 KB |
Output is correct |
31 |
Correct |
122 ms |
7932 KB |
Output is correct |
32 |
Correct |
155 ms |
9408 KB |
Output is correct |
33 |
Correct |
138 ms |
9376 KB |
Output is correct |
34 |
Correct |
138 ms |
9384 KB |
Output is correct |
35 |
Correct |
142 ms |
9388 KB |
Output is correct |