Submission #706817

# Submission time Handle Problem Language Result Execution time Memory
706817 2023-03-07T20:51:40 Z rainboy Drawing (CEOI22_drawing) C
100 / 100
303 ms 38988 KB
#include <stdio.h>
#include <stdlib.h>

#define N	200000

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

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 xx[N], yy[N];

long long cross(int i, int j, int k) {
	return (long long) (xx[j] - xx[i]) * (yy[k] - yy[i]) - (long long) (xx[k] - xx[i]) * (yy[j] - yy[i]);
}

int i1;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			long long c = cross(i1, ii[j], i_);

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int sz[N];

void dfs1(int p, int i) {
	int o;

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

		if (j != p) {
			dfs1(i, j);
			sz[i] += sz[j];
		}
	}
}

int ii_[N];

void dfs2(int *ii, int p, int i) {
	int o, s;

	ii_[i] = ii[0];
	s = 1;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		if (j != p)
			dfs2(ii + s, i, j), s += sz[j];
	}
}

int main() {
	static int ii[N];
	int n, h, i, j;

	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), i--, j--;
		append(i, j), append(j, i);
	}
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	dfs1(-1, 0);
	for (i = 0; i < n; i++)
		ii[i] = i;
	i1 = -1;
	for (i = 0; i < n; i++)
		if (i1 == -1 || xx[i1] > xx[i] || xx[i1] == xx[i] && yy[i1] > yy[i])
			i1 = i;
	ii[0] = i1, ii[i1] = 0;
	sort(ii, 1, n);
	dfs2(ii, -1, 0);
	for (i = 0; i < n; i++)
		printf("%d ", ii_[i] + 1);
	printf("\n");
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:17:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   17 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:101:53: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  101 |   if (i1 == -1 || xx[i1] > xx[i] || xx[i1] == xx[i] && yy[i1] > yy[i])
      |                                     ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
Main.c:87:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:91:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
Main.c:95:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 121 ms 11580 KB Output is correct
2 Correct 126 ms 17936 KB Output is correct
3 Correct 120 ms 15188 KB Output is correct
4 Correct 153 ms 20368 KB Output is correct
5 Correct 118 ms 20692 KB Output is correct
6 Correct 118 ms 11536 KB Output is correct
7 Correct 127 ms 12588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 5 ms 820 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 4 ms 948 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 4 ms 628 KB Output is correct
9 Correct 3 ms 952 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 5 ms 820 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 4 ms 948 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 4 ms 628 KB Output is correct
9 Correct 3 ms 952 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 10 ms 1204 KB Output is correct
16 Correct 9 ms 1816 KB Output is correct
17 Correct 9 ms 1480 KB Output is correct
18 Correct 8 ms 2004 KB Output is correct
19 Correct 9 ms 2004 KB Output is correct
20 Correct 8 ms 1292 KB Output is correct
21 Correct 8 ms 1556 KB Output is correct
22 Correct 8 ms 1168 KB Output is correct
23 Correct 8 ms 1492 KB Output is correct
24 Correct 8 ms 1492 KB Output is correct
25 Correct 9 ms 2096 KB Output is correct
26 Correct 8 ms 1876 KB Output is correct
27 Correct 8 ms 1236 KB Output is correct
28 Correct 9 ms 1428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 5 ms 820 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 4 ms 948 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 4 ms 628 KB Output is correct
9 Correct 3 ms 952 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 3 ms 980 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 10 ms 1204 KB Output is correct
16 Correct 9 ms 1816 KB Output is correct
17 Correct 9 ms 1480 KB Output is correct
18 Correct 8 ms 2004 KB Output is correct
19 Correct 9 ms 2004 KB Output is correct
20 Correct 8 ms 1292 KB Output is correct
21 Correct 8 ms 1556 KB Output is correct
22 Correct 8 ms 1168 KB Output is correct
23 Correct 8 ms 1492 KB Output is correct
24 Correct 8 ms 1492 KB Output is correct
25 Correct 9 ms 2096 KB Output is correct
26 Correct 8 ms 1876 KB Output is correct
27 Correct 8 ms 1236 KB Output is correct
28 Correct 9 ms 1428 KB Output is correct
29 Correct 71 ms 8192 KB Output is correct
30 Correct 79 ms 12912 KB Output is correct
31 Correct 99 ms 11220 KB Output is correct
32 Correct 73 ms 14644 KB Output is correct
33 Correct 82 ms 13372 KB Output is correct
34 Correct 77 ms 8188 KB Output is correct
35 Correct 77 ms 9420 KB Output is correct
36 Correct 68 ms 7056 KB Output is correct
37 Correct 90 ms 11388 KB Output is correct
38 Correct 72 ms 11724 KB Output is correct
39 Correct 79 ms 13444 KB Output is correct
40 Correct 100 ms 11648 KB Output is correct
41 Correct 66 ms 7100 KB Output is correct
42 Correct 73 ms 9524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 11580 KB Output is correct
2 Correct 126 ms 17936 KB Output is correct
3 Correct 120 ms 15188 KB Output is correct
4 Correct 153 ms 20368 KB Output is correct
5 Correct 118 ms 20692 KB Output is correct
6 Correct 118 ms 11536 KB Output is correct
7 Correct 127 ms 12588 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 5 ms 820 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 948 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 724 KB Output is correct
15 Correct 4 ms 628 KB Output is correct
16 Correct 3 ms 952 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
19 Correct 3 ms 852 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 3 ms 816 KB Output is correct
22 Correct 10 ms 1204 KB Output is correct
23 Correct 9 ms 1816 KB Output is correct
24 Correct 9 ms 1480 KB Output is correct
25 Correct 8 ms 2004 KB Output is correct
26 Correct 9 ms 2004 KB Output is correct
27 Correct 8 ms 1292 KB Output is correct
28 Correct 8 ms 1556 KB Output is correct
29 Correct 8 ms 1168 KB Output is correct
30 Correct 8 ms 1492 KB Output is correct
31 Correct 8 ms 1492 KB Output is correct
32 Correct 9 ms 2096 KB Output is correct
33 Correct 8 ms 1876 KB Output is correct
34 Correct 8 ms 1236 KB Output is correct
35 Correct 9 ms 1428 KB Output is correct
36 Correct 71 ms 8192 KB Output is correct
37 Correct 79 ms 12912 KB Output is correct
38 Correct 99 ms 11220 KB Output is correct
39 Correct 73 ms 14644 KB Output is correct
40 Correct 82 ms 13372 KB Output is correct
41 Correct 77 ms 8188 KB Output is correct
42 Correct 77 ms 9420 KB Output is correct
43 Correct 68 ms 7056 KB Output is correct
44 Correct 90 ms 11388 KB Output is correct
45 Correct 72 ms 11724 KB Output is correct
46 Correct 79 ms 13444 KB Output is correct
47 Correct 100 ms 11648 KB Output is correct
48 Correct 66 ms 7100 KB Output is correct
49 Correct 73 ms 9524 KB Output is correct
50 Correct 117 ms 12748 KB Output is correct
51 Correct 258 ms 31780 KB Output is correct
52 Correct 228 ms 27332 KB Output is correct
53 Correct 239 ms 32156 KB Output is correct
54 Correct 294 ms 38988 KB Output is correct
55 Correct 218 ms 20408 KB Output is correct
56 Correct 283 ms 22528 KB Output is correct
57 Correct 37 ms 4428 KB Output is correct
58 Correct 303 ms 27084 KB Output is correct
59 Correct 223 ms 26156 KB Output is correct
60 Correct 289 ms 37636 KB Output is correct
61 Correct 285 ms 30260 KB Output is correct
62 Correct 38 ms 4524 KB Output is correct
63 Correct 247 ms 22192 KB Output is correct