Submission #503306

#TimeUsernameProblemLanguageResultExecution timeMemory
503306rainboyCijanobakterije (COCI21_cijanobakterije)C11
70 / 70
55 ms12536 KiB
#include <stdio.h> #include <stdlib.h> #define N 100000 int max(int a, int b) { return a > b ? a : b; } 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; } char visited[N]; int d1; int dfs(int p, int i) { int o, d_; visited[i] = 1; d_ = 0; for (o = eo[i]; o--; ) { int j = ej[i][o]; if (j != p) { int d = dfs(i, j); d1 = max(d1, d_ + 1 + d), d_ = max(d_, d); } } return d_ + 1; } int main() { int n, m, i, j, ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) ej[i] = (int *) malloc(2 * sizeof *ej[i]); while (m--) { scanf("%d%d", &i, &j), i--, j--; append(i, j), append(j, i); } ans = 0; for (i = 0; i < n; i++) if (!visited[i]) { d1 = 1, dfs(-1, i); ans += d1; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

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