#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1010;
int par[N];
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;
}
void Solve()
{
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";
}
}
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
5548 KB |
Output is correct |
2 |
Correct |
68 ms |
4836 KB |
Output is correct |
3 |
Correct |
64 ms |
4592 KB |
Output is correct |
4 |
Correct |
73 ms |
5592 KB |
Output is correct |
5 |
Correct |
81 ms |
5576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
5548 KB |
Output is correct |
2 |
Correct |
68 ms |
4836 KB |
Output is correct |
3 |
Correct |
64 ms |
4592 KB |
Output is correct |
4 |
Correct |
73 ms |
5592 KB |
Output is correct |
5 |
Correct |
81 ms |
5576 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
139 ms |
9384 KB |
Output is correct |
27 |
Correct |
141 ms |
9400 KB |
Output is correct |
28 |
Correct |
111 ms |
7756 KB |
Output is correct |
29 |
Correct |
134 ms |
9016 KB |
Output is correct |
30 |
Correct |
130 ms |
7976 KB |
Output is correct |
31 |
Correct |
116 ms |
7980 KB |
Output is correct |
32 |
Correct |
141 ms |
9424 KB |
Output is correct |
33 |
Correct |
142 ms |
9448 KB |
Output is correct |
34 |
Correct |
132 ms |
9416 KB |
Output is correct |
35 |
Correct |
143 ms |
9432 KB |
Output is correct |