Submission #1073206

# Submission time Handle Problem Language Result Execution time Memory
1073206 2024-08-24T10:26:06 Z rainboy Infiltration (CCO24_day2problem1) C
25 / 25
4 ms 1372 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100
#define M	1440
#define D	50

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

int dd[] = { 3, 13, 32, 61, 95, 107 };

void test() {
	int a, a_, b, b_, l, d, d_;

	for (a = 0; a <= D; a++)
		for (b = 0; b <= D; b++) {
			a_ = a, b_ = b, d_ = 0, l = 0, d = dd[0];
			while (a_ > 0 || b_ > 0 || a_ != b_) {
				if (l % 2 == 0)
					a_--;
				else
					b_--;
				d_++;
				if (--d == 0)
					d = dd[++l];
			}
			if (d_ * 2 > (a + b) * 15) {
				printf("WA %d %d\n", a, b);
				return;
			}
		}
	printf("AC\n");
}

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;
}

int pp[N], d_;

void dfs(int p, int i, int d) {
	int o;

	pp[i] = p;
	d_ = max(d_, d);
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		if (j != p)
			dfs(i, j, d + 1);
	}
}

int main() {
	static int iii[2][N][M + 1], mm[2][N];
	int n, m, h, i, j, r, t, l, d;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j);
		append(i, j), append(j, i);
	}
	for (r = 0; r < n; r++) {
		d_ = 0, dfs(-1, r, 0);
		if (d_ <= D)
			break;
	}
	m = 0;
	for (t = 0; t < 2; t++)
		for (i = 0; i < n; i++) {
			mm[t][i] = 0, iii[t][i][mm[t][i]] = j = i, l = 0;
			for (l = 0; j != r; l++) {
				d = dd[l];
				if (l % 2 == t)
					for (h = 0; h < d && j != r; h++)
						iii[t][i][++mm[t][i]] = j = pp[j];
				else
					for (h = 0; h < d; h++)
						iii[t][i][++mm[t][i]] = j;
			}
			m = max(m, mm[t][i]);
		}
	printf("%d\n", m * 2);
	for (t = 0; t < 2; t++)
		for (i = 0; i < n; i++)
			for (h = 1; h <= m * 2; h++)
				printf("%d%c", iii[t][i][min((h + 1 - t) / 2, mm[t][i])], h < m * 2 ? ' ' : '\n');
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:41:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   41 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:65:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:69:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   scanf("%d%d", &i, &j);
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1372 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1112 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 2 ms 1112 KB Output is correct
19 Correct 2 ms 1368 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 3 ms 1372 KB Output is correct
25 Correct 4 ms 1368 KB Output is correct