#include <bits/stdc++.h>
using namespace std;
int par[1001];
int Find(int x)
{
if(x == par[x])
{
return x;
}
return par[x] = Find(par[x]);
}
void Unite(int a, int b)
{
a = Find(a), b = Find(b);
if(a == b)
{
return;
}
par[a] = b;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
for(int i = 1; i <= n; i++)
{
par[i] = i;
}
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= n; j++)
{
int x;
cin >> x;
if(Find(x) != Find(j))
{
Unite(x, j);
}
}
}
for(int i = 1; i <= q; i++)
{
int a, b;
cin >> a >> b;
if(Find(a) != Find(b))
{
cout << "NE\n";
}
else
{
cout << "DA\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
1788 KB |
Output is correct |
2 |
Correct |
71 ms |
1596 KB |
Output is correct |
3 |
Correct |
63 ms |
1472 KB |
Output is correct |
4 |
Correct |
71 ms |
1716 KB |
Output is correct |
5 |
Correct |
84 ms |
1692 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 |
292 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 |
2 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 |
292 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 |
2 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 |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 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 |
82 ms |
1788 KB |
Output is correct |
2 |
Correct |
71 ms |
1596 KB |
Output is correct |
3 |
Correct |
63 ms |
1472 KB |
Output is correct |
4 |
Correct |
71 ms |
1716 KB |
Output is correct |
5 |
Correct |
84 ms |
1692 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 |
292 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 |
2 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 |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 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 |
131 ms |
1728 KB |
Output is correct |
27 |
Correct |
132 ms |
1716 KB |
Output is correct |
28 |
Correct |
116 ms |
1456 KB |
Output is correct |
29 |
Correct |
128 ms |
1716 KB |
Output is correct |
30 |
Correct |
130 ms |
8012 KB |
Output is correct |
31 |
Correct |
117 ms |
7972 KB |
Output is correct |
32 |
Correct |
138 ms |
9372 KB |
Output is correct |
33 |
Correct |
142 ms |
9352 KB |
Output is correct |
34 |
Correct |
147 ms |
9376 KB |
Output is correct |
35 |
Correct |
143 ms |
9388 KB |
Output is correct |