Submission #473038

# Submission time Handle Problem Language Result Execution time Memory
473038 2021-09-14T19:04:01 Z rainboy Planinarenje (COCI18_planinarenje) C
80 / 160
307 ms 262148 KB
#include <stdio.h>
#include <stdlib.h>

#define N	5000
#define SMALL	10

int n;

int dp[1 << SMALL + SMALL][SMALL + SMALL]; char adj[SMALL + SMALL][SMALL + SMALL], visited[1 << SMALL + SMALL][SMALL + SMALL];

int dfs(int b, int i) {
	if (!visited[b][i]) {
		int j;

		visited[b][i] = 1;
		for (j = 0; j < n + n; j++)
			if (adj[i][j] && (b & 1 << j) == 0 && !dfs(b | 1 << j, j)) {
				dp[b][i] = 1;
				break;
			}
	}
	return dp[b][i];
}

int *ej[N + N], eo[N + 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 dfs_(int p, int i) {
	int o;

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

		if (j != p && !dfs_(i, j))
			return 1;
	}
	return 0;
}

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

	scanf("%d%d", &n, &m);
	if (n <= SMALL) {
		while (m--) {
			scanf("%d%d", &i, &j), i--, j--;
			adj[i][n + j] = adj[n + j][i] = 1;
		}
		for (i = 0; i < n; i++)
			printf(dfs(1 << i, i) ? "Slavko\n" : "Mirko\n");
	} else {
		for (i = 0; i < n + n; i++)
			ej[i] = (int *) malloc(2 * sizeof *ej[i]);
		while (m--) {
			scanf("%d%d", &i, &j), i--, j--;
			append(i, n + j), append(n + j, i);
		}
		for (i = 0; i < n; i++)
			printf(dfs_(-1, i) ? "Slavko\n" : "Mirko\n");
	}
	return 0;
}

Compilation message

planinarenje.c:9:10: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
    9 | int dp[1 << SMALL + SMALL][SMALL + SMALL]; char adj[SMALL + SMALL][SMALL + SMALL], visited[1 << SMALL + SMALL][SMALL + SMALL];
      |          ^~
planinarenje.c:9:94: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
    9 | int dp[1 << SMALL + SMALL][SMALL + SMALL]; char adj[SMALL + SMALL][SMALL + SMALL], visited[1 << SMALL + SMALL][SMALL + SMALL];
      |                                                                                              ^~
planinarenje.c: In function 'append':
planinarenje.c:30:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
planinarenje.c: In function 'main':
planinarenje.c:50:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
planinarenje.c:53:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |    scanf("%d%d", &i, &j), i--, j--;
      |    ^~~~~~~~~~~~~~~~~~~~~
planinarenje.c:62:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |    scanf("%d%d", &i, &j), i--, j--;
      |    ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 3 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 202 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 188 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 198 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 307 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 197 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -