Submission #922618

#TimeUsernameProblemLanguageResultExecution timeMemory
922618rainboyTravels (LMIO17_keliones)C11
100 / 100
64 ms23888 KiB
#include <stdio.h> #include <stdlib.h> #define N 200000 #define MD 1000000007 void append(int **ej, int *eo, 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 ww[N], *ej[N], eo[N], *fi[N], fo[N], dp[N], dq[N]; int n, m, h, i, j, o, sum, ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &ww[i]); for (i = 0; i < n; i++) { ej[i] = (int *) malloc(2 * sizeof *ej[i]); fi[i] = (int *) malloc(2 * sizeof *fi[i]); } for (h = 0; h < m; h++) { scanf("%d%d", &i, &j), i--, j--; append(ej, eo, i, j), append(fi, fo, j, i); } sum = 0; for (j = 0; j < n; j++) { dp[j] = (sum + 1) % MD; for (o = fo[j]; o--; ) { i = fi[j][o]; dp[j] = (dp[j] - dp[i] + MD) % MD; } sum = (sum + dp[j]) % MD; } sum = 0; for (i = n - 1; i >= 0; i--) { dq[i] = (sum + 1) % MD; for (o = eo[i]; o--; ) { j = ej[i][o]; dq[i] = (dq[i] - dq[j] + MD) % MD; } sum = (sum + dq[i]) % MD; } ans = 0; for (i = 0; i < n; i++) ans = (ans + ww[i] * (((long long) dp[i] * dq[i] - 1 + MD) % MD)) % MD; printf("%d\n", ans); return 0; }

Compilation message (stderr)

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