#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
struct node{
long long parent;
long long rank;
};
node v[200005];
long long find(long long u){
if(u != v[u].parent){
v[u].parent = find(v[u].parent);
}
return v[u].parent;
}
void merge(long long x, long long y){
long long px = find(x);
long long py = find(y);
if(v[px].rank > v[py].rank){
v[py].parent = px;
}else{
v[px].parent = py;
}
if(v[px].rank == v[py].rank){
v[py].rank++;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> q;
for (int i = 1; i <= n; ++i)
{
v[i].parent = i;
v[i].rank = 0;
}
for (int i = 1; i <= m; ++i)
{
for (int j = 1; j <= n; ++j)
{
int t;
cin >> t;
merge(t, j);
}
}
while(q--){
int l, r;
cin >> l >> r;
if(find(l) == find(r)){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
1756 KB |
Output is correct |
2 |
Correct |
76 ms |
1600 KB |
Output is correct |
3 |
Correct |
69 ms |
1520 KB |
Output is correct |
4 |
Correct |
89 ms |
1812 KB |
Output is correct |
5 |
Correct |
80 ms |
1700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
1756 KB |
Output is correct |
2 |
Correct |
76 ms |
1600 KB |
Output is correct |
3 |
Correct |
69 ms |
1520 KB |
Output is correct |
4 |
Correct |
89 ms |
1812 KB |
Output is correct |
5 |
Correct |
80 ms |
1700 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
155 ms |
1820 KB |
Output is correct |
27 |
Correct |
146 ms |
1768 KB |
Output is correct |
28 |
Correct |
115 ms |
1476 KB |
Output is correct |
29 |
Correct |
160 ms |
1732 KB |
Output is correct |
30 |
Correct |
129 ms |
1476 KB |
Output is correct |
31 |
Correct |
142 ms |
1468 KB |
Output is correct |
32 |
Correct |
164 ms |
1724 KB |
Output is correct |
33 |
Correct |
155 ms |
9412 KB |
Output is correct |
34 |
Correct |
152 ms |
9400 KB |
Output is correct |
35 |
Correct |
154 ms |
9412 KB |
Output is correct |