Submission #528348

# Submission time Handle Problem Language Result Execution time Memory
528348 2022-02-20T06:25:51 Z ivls Kutije (COCI21_kutije) C++17
70 / 70
175 ms 9400 KB
#include <bits/stdc++.h>

using namespace std;

struct dsu
{
	int n, p[1010];
	
	void init(int nn)
	{
		n = nn;
		for (int i = 1; i <= n; i++) p[i] = i;
	}
	
	int get(int v) { return v == p[v] ? v : p[v] = get(p[v]); }
	
	bool same(int u, int v) { return get(u) == get(v); }
	
	void uni(int u, int v) { u = get(u); v = get(v); p[u] = v; }
};

int main() 
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n, m, q;
	cin >> n >> m >> q;
	int p[n + 1];
	dsu d;
	d.init(n);
	while (m--)
		for (int i = 1; i <= n; i++) { int v; cin >> v; d.uni(i, v); }
	while (q--)
	{
		int a, b;
		cin >> a >> b;
		cout << (d.same(a, b) ? "DA" : "NE") << '\n'; 
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:6: warning: unused variable 'p' [-Wunused-variable]
   28 |  int p[n + 1];
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5516 KB Output is correct
2 Correct 82 ms 4856 KB Output is correct
3 Correct 66 ms 4584 KB Output is correct
4 Correct 80 ms 5584 KB Output is correct
5 Correct 105 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5516 KB Output is correct
2 Correct 82 ms 4856 KB Output is correct
3 Correct 66 ms 4584 KB Output is correct
4 Correct 80 ms 5584 KB Output is correct
5 Correct 105 ms 5592 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 138 ms 9400 KB Output is correct
27 Correct 149 ms 9372 KB Output is correct
28 Correct 140 ms 7836 KB Output is correct
29 Correct 156 ms 9176 KB Output is correct
30 Correct 136 ms 7960 KB Output is correct
31 Correct 119 ms 8096 KB Output is correct
32 Correct 149 ms 9380 KB Output is correct
33 Correct 173 ms 9372 KB Output is correct
34 Correct 137 ms 9368 KB Output is correct
35 Correct 175 ms 9372 KB Output is correct