Submission #457949

#TimeUsernameProblemLanguageResultExecution timeMemory
457949rainboyStations (IOI20_stations)C++17
0 / 100
3118 ms2097156 KiB
#include "stations.h" #include <stdlib.h> #include <vector> using namespace std; typedef vector<int> vi; const int N = 1000; 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 ta[N], tb[N]; void dfs(int p, int i) { static int time; int o; ta[i] = time++; for (o = eo[i]; o--; ) { int j = ej[i][o]; if (j != p) dfs(i, j); } tb[i] = time - 1; } vi label(int n, int k, vi uu, vi vv) { int h, i; vi labels(n); for (i = 0; i < n; i++) ej[i] = (int *) malloc(2 * sizeof *ej[i]); for (h = 0; h < n - 1; h++) append(uu[h], vv[h]), append(vv[h], uu[h]); dfs(-1, 0); for (i = 0; i < n; i++) labels[i] = ta[i] * N + tb[i]; return labels; } int find_next_station(int s, int t, vi cc) { int m = cc.size(), h; for (h = 0; h < m; h++) if (cc[h] / N > s / N && cc[h] / N <= t / N && t / N <= cc[h] % N) return cc[h]; for (h = 0; h < m; h++) if (cc[h] / N < s / N) return cc[h]; return -1; }

Compilation message (stderr)

stations.cpp: In function 'void append(int, int)':
stations.cpp:15:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
#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...