Submission #730989

#TimeUsernameProblemLanguageResultExecution timeMemory
730989rainboyCheap flights (LMIO18_pigus_skrydziai)C11
100 / 100
855 ms33108 KiB
#include <stdio.h> #include <stdlib.h> #define N 300000 long long max(long long a, long long b) { return a > b ? a : b; } int *ej[N], *ew[N], eo[N]; void append(int i, int j, int w) { int o = eo[i]++; if (o >= 2 && (o & o - 1) == 0) { ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]); ew[i] = (int *) realloc(ew[i], o * 2 * sizeof *ew[i]); } ej[i][o] = j, ew[i][o] = w; } int main() { static int ww[N]; int n, m, h, i, j, k, w, w_, o, o_; long long sum, ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { ej[i] = (int *) malloc(2 * sizeof *ej[i]); ew[i] = (int *) malloc(2 * sizeof *ew[i]); } for (h = 0; h < m; h++) { scanf("%d%d%d", &i, &j, &w), i--, j--; append(i, j, w), append(j, i, w); } ans = 0; for (i = 0; i < n; i++) { sum = 0; for (o = eo[i]; o--; ) { j = ej[i][o], w = ew[i][o]; sum += w; ww[j] = w; } ans = max(ans, sum); for (o = eo[i]; o--; ) { j = ej[i][o], w = ew[i][o]; if (eo[j] < eo[i] || eo[j] == eo[i] && j < i) for (o_ = eo[j]; o_--; ) { k = ej[j][o_], w_ = ew[j][o_]; if (k != i) ans = max(ans, (long long) w + w_ + ww[k]); } } for (o = eo[i]; o--; ) { j = ej[i][o]; ww[j] = 0; } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

pigus_skrydziai.c: In function 'append':
pigus_skrydziai.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0) {
      |                     ~~^~~
pigus_skrydziai.c: In function 'main':
pigus_skrydziai.c:45:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   45 |    if (eo[j] < eo[i] || eo[j] == eo[i] && j < i)
      |                         ~~~~~~~~~~~~~~~^~~~~~~~
pigus_skrydziai.c:25:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d%d%d", &i, &j, &w), 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...