Submission #862551

# Submission time Handle Problem Language Result Execution time Memory
862551 2023-10-18T13:29:07 Z Cyber_Wolf Kutije (COCI21_kutije) C++17
70 / 70
911 ms 11900 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define lg long long 
 
const lg N = 2e5+5;
 

lg par[N], compSize[N];
lg get(lg src)
{
	if(par[src] == src)	return src;
	return par[src] = get(par[src]);
}
 
void join(lg u, lg v)
{
    u = get(u);
    v = get(v);
    if(u == v)    return;
    if(compSize[u] > compSize[v])    swap(u, v);
    par[u] = v;
    compSize[v] += compSize[u];
    return;
}

int main()
{
	lg n, m, q;
	cin >> n >> m >> q;
	for(int i = 1; i <= n; i++)	par[i] = i, compSize[i] = 1;
	for(int i = 0; i < m; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			lg x;
			cin >> x;
			join(x, j);
		}
	}
	while(q--)
	{
		lg a, b;
		cin >> a >> b;
		cout << (get(a) == get(b) ? "DA" : "NE") << '\n';
	}
}
 
/*
-2 -1 -2 -1 1 -2 -2 -2 -1 -2 -1 -2 -1 -1 -1 -1
-2 -1 -2 -1 -2 -2 -2 -2 -2 -2 -2 -2 0 -2 -2 -2
-2 -2 -2 -2 -1 -2 -1 -2 0 -2 -2 -2 -1 -2 -1 -2
2
*/
# Verdict Execution time Memory Grader output
1 Correct 708 ms 8016 KB Output is correct
2 Correct 621 ms 6996 KB Output is correct
3 Correct 587 ms 6736 KB Output is correct
4 Correct 723 ms 7760 KB Output is correct
5 Correct 731 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2504 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2528 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2520 KB Output is correct
10 Correct 2 ms 2524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2504 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2528 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 2520 KB Output is correct
10 Correct 2 ms 2524 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2524 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2508 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 708 ms 8016 KB Output is correct
2 Correct 621 ms 6996 KB Output is correct
3 Correct 587 ms 6736 KB Output is correct
4 Correct 723 ms 7760 KB Output is correct
5 Correct 731 ms 7768 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2504 KB Output is correct
9 Correct 2 ms 2392 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2528 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2520 KB Output is correct
15 Correct 2 ms 2524 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2524 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2508 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 867 ms 11900 KB Output is correct
27 Correct 857 ms 11576 KB Output is correct
28 Correct 724 ms 10068 KB Output is correct
29 Correct 830 ms 11236 KB Output is correct
30 Correct 741 ms 10096 KB Output is correct
31 Correct 714 ms 10072 KB Output is correct
32 Correct 880 ms 11352 KB Output is correct
33 Correct 911 ms 11596 KB Output is correct
34 Correct 884 ms 11568 KB Output is correct
35 Correct 880 ms 11548 KB Output is correct