Submission #473038

#TimeUsernameProblemLanguageResultExecution timeMemory
473038rainboyPlaninarenje (COCI18_planinarenje)C11
80 / 160
307 ms262148 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...