Submission #473595

#TimeUsernameProblemLanguageResultExecution timeMemory
473595rainboyAlkemija (COCI18_alkemija)C11
80 / 80
78 ms9040 KiB
#include <stdio.h> #include <stdlib.h> #define N 100000 #define K 100000 int *hh[N], kk[N], *ii[K], nn[K]; void append(int i, int h) { int g = kk[i]++; if (g >= 2 && (g & g - 1) == 0) hh[i] = (int *) realloc(hh[i], g * 2 * sizeof *hh[i]); hh[i][g] = h; } int dd[K]; void dfs_i(int i); void dfs_h(int h) { if (--dd[h] == 0) { int g; for (g = 0; g < nn[h]; g++) dfs_i(ii[h][g]); } } char in[N]; void dfs_i(int i) { if (in[i] != 1) { int g; in[i] = 1; for (g = 0; g < kk[i]; g++) dfs_h(hh[i][g]); } } int main() { int n, m, k, h, i, cnt; scanf("%d%d", &n, &m); while (m--) { scanf("%d", &i), i--; in[i] = -1; } for (i = 0; i < n; i++) hh[i] = (int *) malloc(2 * sizeof *hh[i]); scanf("%d", &k); for (h = 0; h < k; h++) { scanf("%d%d", &m, &nn[h]); dd[h] = m; while (m--) { scanf("%d", &i), i--; append(i, h); } ii[h] = (int *) malloc(nn[h] * sizeof *ii[h]); for (i = 0; i < nn[h]; i++) scanf("%d", &ii[h][i]), ii[h][i]--; } for (i = 0; i < n; i++) if (in[i] == -1) dfs_i(i); cnt = 0; for (i = 0; i < n; i++) if (in[i]) cnt++; printf("%d\n", cnt); for (i = 0; i < n; i++) if (in[i]) printf("%d ", i + 1); printf("\n"); return 0; }

Compilation message (stderr)

alkemija.c: In function 'append':
alkemija.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |  if (g >= 2 && (g & g - 1) == 0)
      |                     ~~^~~
alkemija.c: In function 'main':
alkemija.c:45:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
alkemija.c:47:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
alkemija.c:52:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d", &k);
      |  ^~~~~~~~~~~~~~~
alkemija.c:54:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d%d", &m, &nn[h]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
alkemija.c:57:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |    scanf("%d", &i), i--;
      |    ^~~~~~~~~~~~~~~
alkemija.c:62:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |    scanf("%d", &ii[h][i]), ii[h][i]--;
      |    ^~~~~~~~~~~~~~~~~~~~~~
#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...