Submission #482194

#TimeUsernameProblemLanguageResultExecution timeMemory
482194rainboyBirmingham (COCI20_birmingham)C11
70 / 70
144 ms9520 KiB
#include <stdio.h> #include <stdlib.h> #define N 100000 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 main() { static int dd[N], tt[N], qu[N]; int n, m, q, k, h, i, j, d, t, head, cnt; scanf("%d%d%d%d", &n, &m, &q, &k); for (i = 0; i < n; i++) dd[i] = n; head = cnt = 0; while (q--) { scanf("%d", &i), i--; if (dd[i] == n) dd[i] = 0, qu[head + cnt++] = i; } for (d = 0, t = 0; d < n; d++) { while (t * (t + 1) / 2 * k < d) t++; tt[d] = t; } for (i = 0; i < n; i++) ej[i] = (int *) malloc(2 * sizeof *ej[i]); for (h = 0; h < m; h++) { scanf("%d%d", &i, &j), i--, j--; append(i, j), append(j, i); } while (cnt) { int o; i = qu[cnt--, head++], d = dd[i] + 1; for (o = eo[i]; o--; ) { int j = ej[i][o]; if (dd[j] > d) dd[j] = d, qu[head + cnt++] = j; } } for (i = 0; i < n; i++) printf("%d ", tt[dd[i]]); printf("\n"); return 0; }

Compilation message (stderr)

birmingham.c: In function 'append':
birmingham.c:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
birmingham.c: In function 'main':
birmingham.c:20:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%d%d%d%d", &n, &m, &q, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
birmingham.c:25:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
birmingham.c:37:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...