#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl '\n'
int n, m, q;
struct DSU{
vector<int> bs;
void init(int _n) {
bs.assign(_n+5,0);
for (int i = 1; i <= _n; ++i) {
bs[i] = i;
}
}
int find(int p) {
if (p == bs[p]) return p;
return bs[p] = find(bs[p]);
}
void add(int u, int v) {
int x = find(u), y = find(v);
bs[x] = y;
}
} dsu;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n>>m>>q;
dsu.init(n);
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
int p; cin>>p;
dsu.add(p,j);
}
}
while(q--) {
int u, v; cin>>u>>v;
if (dsu.find(u) == dsu.find(v)) cout<<"DA"<<endl;
else cout<<"NE"<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
1776 KB |
Output is correct |
2 |
Correct |
73 ms |
1524 KB |
Output is correct |
3 |
Correct |
79 ms |
1500 KB |
Output is correct |
4 |
Correct |
93 ms |
1796 KB |
Output is correct |
5 |
Correct |
84 ms |
1716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
1776 KB |
Output is correct |
2 |
Correct |
73 ms |
1524 KB |
Output is correct |
3 |
Correct |
79 ms |
1500 KB |
Output is correct |
4 |
Correct |
93 ms |
1796 KB |
Output is correct |
5 |
Correct |
84 ms |
1716 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
141 ms |
1700 KB |
Output is correct |
27 |
Correct |
148 ms |
1740 KB |
Output is correct |
28 |
Correct |
113 ms |
1456 KB |
Output is correct |
29 |
Correct |
134 ms |
1712 KB |
Output is correct |
30 |
Correct |
129 ms |
1456 KB |
Output is correct |
31 |
Correct |
121 ms |
1484 KB |
Output is correct |
32 |
Correct |
158 ms |
1724 KB |
Output is correct |
33 |
Correct |
158 ms |
1768 KB |
Output is correct |
34 |
Correct |
138 ms |
1796 KB |
Output is correct |
35 |
Correct |
143 ms |
1712 KB |
Output is correct |