Submission #503306

# Submission time Handle Problem Language Result Execution time Memory
503306 2022-01-07T16:01:27 Z rainboy Cijanobakterije (COCI21_cijanobakterije) C
70 / 70
55 ms 12536 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000

int max(int a, int b) { return a > b ? a : b; }

int *ej[N], eo[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

char visited[N]; int d1;

int dfs(int p, int i) {
	int o, d_;

	visited[i] = 1;
	d_ = 0;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		if (j != p) {
			int d = dfs(i, j);

			d1 = max(d1, d_ + 1 + d), d_ = max(d_, d);
		}
	}
	return d_ + 1;
}

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

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	while (m--) {
		scanf("%d%d", &i, &j), i--, j--;
		append(i, j), append(j, i);
	}
	ans = 0;
	for (i = 0; i < n; i++)
		if (!visited[i]) {
			d1 = 1, dfs(-1, i);
			ans += d1;
		}
	printf("%d\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 972 KB Output is correct
2 Correct 12 ms 1780 KB Output is correct
3 Correct 27 ms 2552 KB Output is correct
4 Correct 22 ms 3404 KB Output is correct
5 Correct 36 ms 4068 KB Output is correct
6 Correct 41 ms 4928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 12536 KB Output is correct
2 Correct 3 ms 972 KB Output is correct
3 Correct 5 ms 1740 KB Output is correct
4 Correct 8 ms 2464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 5 ms 1100 KB Output is correct
6 Correct 9 ms 1920 KB Output is correct
7 Correct 9 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 972 KB Output is correct
2 Correct 12 ms 1780 KB Output is correct
3 Correct 27 ms 2552 KB Output is correct
4 Correct 22 ms 3404 KB Output is correct
5 Correct 36 ms 4068 KB Output is correct
6 Correct 41 ms 4928 KB Output is correct
7 Correct 30 ms 12536 KB Output is correct
8 Correct 3 ms 972 KB Output is correct
9 Correct 5 ms 1740 KB Output is correct
10 Correct 8 ms 2464 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 284 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 5 ms 1100 KB Output is correct
16 Correct 9 ms 1920 KB Output is correct
17 Correct 9 ms 2764 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 55 ms 4852 KB Output is correct
30 Correct 15 ms 4580 KB Output is correct
31 Correct 22 ms 4572 KB Output is correct
32 Correct 14 ms 4684 KB Output is correct
33 Correct 44 ms 4636 KB Output is correct
34 Correct 18 ms 4684 KB Output is correct
35 Correct 41 ms 4568 KB Output is correct
36 Correct 24 ms 4684 KB Output is correct
37 Correct 29 ms 4696 KB Output is correct
38 Correct 29 ms 4688 KB Output is correct
39 Correct 30 ms 4544 KB Output is correct