/**
* author: NotLinux
* created: 06.09.2022 ~ 13:48:17
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include "/home/notlinux/debug.h"
#else
#define debug(x...) void(37)
#endif
vector < int > par;
int find(int a){
if(par[a] == a)return a;
par[a] = find(par[a]);
return par[a];
}
void merge(int a, int b){
par[find(a)] = find(b);
}
void solve(){
int n,m,q;cin >> n >> m >> q;
par.resize(2*n);
iota(par.begin(),par.end(),0LL);
while(m--){
for(int i = 1;i<=n;i++){
int dummy;cin >> dummy;
merge(dummy , i);
}
}
while(q--){
int a,b;cin >> a >> b;
cout << (find(a)==find(b)?"DA":"NE") << endl;
}
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
int tt=1;
//cin >> tt;
while(tt--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
614 ms |
5672 KB |
Output is correct |
2 |
Correct |
543 ms |
4840 KB |
Output is correct |
3 |
Correct |
494 ms |
4748 KB |
Output is correct |
4 |
Correct |
616 ms |
5704 KB |
Output is correct |
5 |
Correct |
620 ms |
5620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 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 |
340 KB |
Output is correct |
12 |
Correct |
2 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 |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
614 ms |
5672 KB |
Output is correct |
2 |
Correct |
543 ms |
4840 KB |
Output is correct |
3 |
Correct |
494 ms |
4748 KB |
Output is correct |
4 |
Correct |
616 ms |
5704 KB |
Output is correct |
5 |
Correct |
620 ms |
5620 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 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 |
2 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 |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
352 KB |
Output is correct |
26 |
Correct |
680 ms |
9432 KB |
Output is correct |
27 |
Correct |
664 ms |
9420 KB |
Output is correct |
28 |
Correct |
582 ms |
7876 KB |
Output is correct |
29 |
Correct |
662 ms |
9008 KB |
Output is correct |
30 |
Correct |
584 ms |
8112 KB |
Output is correct |
31 |
Correct |
556 ms |
8012 KB |
Output is correct |
32 |
Correct |
672 ms |
9460 KB |
Output is correct |
33 |
Correct |
687 ms |
9324 KB |
Output is correct |
34 |
Correct |
704 ms |
9440 KB |
Output is correct |
35 |
Correct |
819 ms |
9492 KB |
Output is correct |