// In the name of God, the Most Gracious, the Most Merciful.
// iflbot(); - @yavuzskarahan
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
short n, m, a, b;
int q;
short parent[1002];
inline short find(short a){
if (a==parent[a]) return a;
else return parent[a] = find(parent[a]);
}
inline void unite(short a, short b){
a = find(a);
b = find(b);
parent[b] = a;
return;
}
inline int solve(){
cin >> n >> m >> q;
for(short i = 1; i <= n; i++) parent[i] = i;
for(short i = 1; i <= m; i++){
for(short j = 1; j <= n; j++){
cin >> a;
unite(j,a);
}
}
while(q--){
cin >> a >> b;
if (find(a) == find(b)) cout << "DA" << endl;
else cout << "NE" << endl;
}
return 0;
}
int main() {
fast;
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
722 ms |
1868 KB |
Output is correct |
2 |
Correct |
623 ms |
1612 KB |
Output is correct |
3 |
Correct |
594 ms |
1608 KB |
Output is correct |
4 |
Correct |
720 ms |
1864 KB |
Output is correct |
5 |
Correct |
726 ms |
1864 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 |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 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 |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 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 |
508 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 |
722 ms |
1868 KB |
Output is correct |
2 |
Correct |
623 ms |
1612 KB |
Output is correct |
3 |
Correct |
594 ms |
1608 KB |
Output is correct |
4 |
Correct |
720 ms |
1864 KB |
Output is correct |
5 |
Correct |
726 ms |
1864 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 |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
2 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 |
508 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 |
759 ms |
1864 KB |
Output is correct |
27 |
Correct |
783 ms |
1864 KB |
Output is correct |
28 |
Correct |
692 ms |
1492 KB |
Output is correct |
29 |
Correct |
750 ms |
1864 KB |
Output is correct |
30 |
Correct |
658 ms |
1584 KB |
Output is correct |
31 |
Correct |
619 ms |
1668 KB |
Output is correct |
32 |
Correct |
759 ms |
1864 KB |
Output is correct |
33 |
Correct |
782 ms |
1864 KB |
Output is correct |
34 |
Correct |
755 ms |
1708 KB |
Output is correct |
35 |
Correct |
760 ms |
1864 KB |
Output is correct |