#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()
{
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 |
784 ms |
1736 KB |
Output is correct |
2 |
Correct |
668 ms |
4916 KB |
Output is correct |
3 |
Correct |
643 ms |
4724 KB |
Output is correct |
4 |
Correct |
784 ms |
5612 KB |
Output is correct |
5 |
Correct |
798 ms |
5580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
324 KB |
Output is correct |
15 |
Correct |
3 ms |
316 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
784 ms |
1736 KB |
Output is correct |
2 |
Correct |
668 ms |
4916 KB |
Output is correct |
3 |
Correct |
643 ms |
4724 KB |
Output is correct |
4 |
Correct |
784 ms |
5612 KB |
Output is correct |
5 |
Correct |
798 ms |
5580 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
316 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
324 KB |
Output is correct |
20 |
Correct |
3 ms |
316 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
978 ms |
9348 KB |
Output is correct |
27 |
Correct |
980 ms |
9412 KB |
Output is correct |
28 |
Correct |
787 ms |
7936 KB |
Output is correct |
29 |
Execution timed out |
1078 ms |
8976 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |