Submission #545911

#TimeUsernameProblemLanguageResultExecution timeMemory
545911rainboyOne-Way Streets (CEOI17_oneway)C11
100 / 100
103 ms13728 KiB
#include <stdio.h> #include <stdlib.h> #define N 100000 #define M 100000 int min(int a, int b) { return a < b ? a : b; } int ii[M], jj[M]; char cc[M + 1]; 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; } int ta[N], tb[N], kk[N]; void dfs(int f, int i) { static int time; int o; ta[i] = tb[i] = ++time; for (o = eo[i]; o--; ) { int h = eh[i][o], j = i ^ ii[h] ^ jj[h]; if (h != f) { if (!ta[j]) { dfs(h, j); if (tb[j] != ta[j] || kk[j] == 0) cc[h] = 'B'; else cc[h] = (i == ii[h]) == (kk[j] < 0) ? 'R' : 'L'; tb[i] = min(tb[i], tb[j]); kk[i] += kk[j]; } else { cc[h] = 'B'; tb[i] = min(tb[i], ta[j]); } } } } int main() { int n, m, q, h, i, j; 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--; ii[h] = i, jj[h] = j; append(i, h), append(j, h); } scanf("%d", &q); while (q--) { scanf("%d%d", &i, &j), i--, j--; kk[i]++, kk[j]--; } for (i = 0; i < n; i++) if (!ta[i]) dfs(-1, i); printf("%s\n", cc); return 0; }

Compilation message (stderr)

oneway.c: In function 'append':
oneway.c:15:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
oneway.c: In function 'main':
oneway.c:50:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
oneway.c:54:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
oneway.c:58:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
oneway.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   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...