Submission #503211

# Submission time Handle Problem Language Result Execution time Memory
503211 2022-01-07T14:00:12 Z rainboy Kutije (COCI21_kutije) C
70 / 70
226 ms 9124 KB
#include <stdio.h>
#include <string.h>

#define N	1000

int ds[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int main() {
	int n, m, q, i, j;

	scanf("%d%d%d", &n, &m, &q);
	memset(ds, -1, n * sizeof *ds);
	while (m--)
		for (i = 0; i < n; i++) {
			scanf("%d", &j), j--;
			join(i, j);
		}
	while (q--) {
		scanf("%d%d", &i, &j), i--, j--;
		printf(find(i) == find(j) ? "DA\n" : "NE\n");
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d%d%d", &n, &m, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:33:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |    scanf("%d", &j), j--;
      |    ^~~~~~~~~~~~~~~
Main.c:37:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 114 ms 4636 KB Output is correct
2 Correct 93 ms 4748 KB Output is correct
3 Correct 92 ms 4568 KB Output is correct
4 Correct 109 ms 5432 KB Output is correct
5 Correct 120 ms 5380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 284 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 4636 KB Output is correct
2 Correct 93 ms 4748 KB Output is correct
3 Correct 92 ms 4568 KB Output is correct
4 Correct 109 ms 5432 KB Output is correct
5 Correct 120 ms 5380 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 284 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 201 ms 8624 KB Output is correct
27 Correct 210 ms 8880 KB Output is correct
28 Correct 184 ms 7284 KB Output is correct
29 Correct 194 ms 8544 KB Output is correct
30 Correct 182 ms 7580 KB Output is correct
31 Correct 169 ms 7456 KB Output is correct
32 Correct 202 ms 8900 KB Output is correct
33 Correct 226 ms 8948 KB Output is correct
34 Correct 195 ms 9124 KB Output is correct
35 Correct 204 ms 8660 KB Output is correct