Submission #536644

# Submission time Handle Problem Language Result Execution time Memory
536644 2022-03-13T16:18:48 Z rainboy 전압 (JOI14_voltage) C
100 / 100
131 ms 16340 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000
#define M	200000

int ij[M];
int *eh[N], eo[N];

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

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

char visited[N]; int dd[N], kk[N], k;

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

	visited[i] = 1, dd[i] = d;
	for (o = eo[i]; o--; ) {
		int h = eh[i][o];

		if (h != f) {
			int j = i ^ ij[h];

			if (!visited[j]) {
				dfs(h, j, d + 1);
				kk[i] += kk[j];
			} else if (dd[j] < dd[i]) {
				if ((dd[i] - dd[j]) % 2 == 0)
					kk[i]++, k++;
				else
					kk[i]--;
			} else {
				if ((dd[i] - dd[j]) % 2 == 0)
					kk[i]--;
				else
					kk[i]++;
			}
		}
	}
}

int main() {
	int n, m, h, i, j, cnt;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		eh[i] = (int *) malloc(2 * sizeof *eh[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		ij[h] = i ^ j;
		append(i, h), append(j, h);
	}
	for (i = 0; i < n; i++)
		if (!visited[i])
			dfs(-1, i, 0);
	cnt = k == 1 ? 1 : 0;
	for (i = 0; i < n; i++)
		if (dd[i] > 0 && kk[i] == k)
			cnt++;
	printf("%d\n", cnt);
	return 0;
}

Compilation message

voltage.c: In function 'append':
voltage.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
voltage.c: In function 'main':
voltage.c:51:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
voltage.c:55:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 356 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 5968 KB Output is correct
2 Correct 58 ms 11496 KB Output is correct
3 Correct 45 ms 7172 KB Output is correct
4 Correct 55 ms 13024 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 59 ms 9688 KB Output is correct
7 Correct 69 ms 14796 KB Output is correct
8 Correct 70 ms 14776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5972 KB Output is correct
2 Correct 33 ms 14780 KB Output is correct
3 Correct 34 ms 14768 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 36 ms 9384 KB Output is correct
6 Correct 56 ms 7272 KB Output is correct
7 Correct 64 ms 10492 KB Output is correct
8 Correct 56 ms 11340 KB Output is correct
9 Correct 46 ms 11852 KB Output is correct
10 Correct 50 ms 9812 KB Output is correct
11 Correct 51 ms 7244 KB Output is correct
12 Correct 72 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 7096 KB Output is correct
2 Correct 61 ms 16340 KB Output is correct
3 Correct 5 ms 4608 KB Output is correct
4 Correct 55 ms 11740 KB Output is correct
5 Correct 84 ms 12728 KB Output is correct
6 Correct 80 ms 11084 KB Output is correct
7 Correct 91 ms 14356 KB Output is correct
8 Correct 86 ms 15232 KB Output is correct
9 Correct 97 ms 11908 KB Output is correct
10 Correct 131 ms 14700 KB Output is correct
11 Correct 115 ms 12332 KB Output is correct
12 Correct 94 ms 14760 KB Output is correct
13 Correct 78 ms 11532 KB Output is correct
14 Correct 104 ms 15396 KB Output is correct
15 Correct 125 ms 14912 KB Output is correct
16 Correct 90 ms 13560 KB Output is correct
17 Correct 81 ms 13084 KB Output is correct
18 Correct 78 ms 13260 KB Output is correct