Submission #571308

# Submission time Handle Problem Language Result Execution time Memory
571308 2022-06-01T17:02:35 Z Vanilla Swapping Cities (APIO20_swap) C++17
36 / 100
2000 ms 48524 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 200;
int extra = 1e5 + 1;
const int lg = 18;
int deg [maxn];
int dad [maxn];
vector <int> val (maxn, 1e9);
vector <bool> good (maxn, 0);
vector <int> cmp [maxn];
vector <int> depth (maxn);
int up[maxn][lg];
 
void dfs (int u, int vs) {
    if (good[u]) vs = val[u];
    val[u] = vs;
    for (auto v: cmp[u]) {
        depth[v] = depth[u] + 1;
        up[v][0] = u;
        for (int i = 1; i < lg; i++){
            up[v][i] = up[up[v][i-1]][i-1];
        }
        dfs(v, vs);
    }
}
 
int lca (int x, int y) {
    if (depth[x] < depth[y]) {
        swap(x, y);
    }
    int k = depth[x] - depth[y];
    for (int i = 0; i < lg; i++){
        if (k & (1 << i)) {
            x = up[x][i];
        }
    }
    if (x == y) return x;
    for (int i = lg - 1; i >= 0; i--) {
        if (up[x][i] != up[y][i]) {
            x = up[x][i];
            y = up[y][i];
        }
    }
    return up[x][0];
}
 
 
int get_dad (int x) {
  return dad[x] = (dad[x] == x ? x: get_dad(dad[x]));
}
 
bool propagate (int u) {
  for (int v: cmp[u]) {
    good[u]= good[u] | propagate(v);
  }
  return good[u];
}
 
struct edg {
  int x,y,cost;
};
 
bool comp (edg &a, edg &b) {
  return a.cost < b.cost;
}
 
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w) {
  vector <edg> eg;
  for (int i = 0; i < maxn; i++){
    dad[i] = i;
    for (int j = 0; j < lg; j++){
      up[i][j] = maxn-1;
    }
  }
  for (int i = 0; i < m; i++){
    eg.push_back({u[i], v[i], w[i]});
  }
  sort(eg.begin(), eg.end(), comp);
  for (auto [u,v,cost]: eg) {
    int p1 = get_dad(u);
    int p2 = get_dad(v);
    deg[u]++;
    deg[v]++;
    val[++extra] = cost;
    dad[p1] = extra;
    dad[p2] = extra;
    cmp[extra].push_back(p1);
    cmp[extra].push_back(p2);
    if (p1 == p2 || deg[u] >= 3 || deg[v] >= 3) {
      good[extra] = 1;
    }
  
  }
  propagate(extra);
  dfs(extra, 1e9);

}
 
int getMinimumFuelCapacity(int x, int y) {
  int k = lca(x,y);
  if (val[k] == 1e9) return -1;
  return val[k];
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31956 KB Output is correct
2 Correct 16 ms 31956 KB Output is correct
3 Correct 15 ms 31992 KB Output is correct
4 Correct 17 ms 32084 KB Output is correct
5 Correct 17 ms 32128 KB Output is correct
6 Correct 18 ms 32084 KB Output is correct
7 Correct 17 ms 32024 KB Output is correct
8 Correct 16 ms 32084 KB Output is correct
9 Correct 111 ms 37532 KB Output is correct
10 Correct 128 ms 38768 KB Output is correct
11 Correct 122 ms 38656 KB Output is correct
12 Correct 135 ms 39032 KB Output is correct
13 Correct 105 ms 42924 KB Output is correct
14 Correct 114 ms 37684 KB Output is correct
15 Correct 225 ms 40324 KB Output is correct
16 Correct 222 ms 40284 KB Output is correct
17 Correct 227 ms 40604 KB Output is correct
18 Correct 296 ms 44492 KB Output is correct
19 Correct 90 ms 36420 KB Output is correct
20 Correct 286 ms 40632 KB Output is correct
21 Correct 283 ms 40700 KB Output is correct
22 Correct 295 ms 41120 KB Output is correct
23 Correct 346 ms 45040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31956 KB Output is correct
2 Correct 16 ms 31956 KB Output is correct
3 Correct 238 ms 48008 KB Output is correct
4 Correct 232 ms 48508 KB Output is correct
5 Correct 260 ms 48428 KB Output is correct
6 Correct 233 ms 48396 KB Output is correct
7 Correct 248 ms 48524 KB Output is correct
8 Correct 238 ms 48016 KB Output is correct
9 Correct 246 ms 48408 KB Output is correct
10 Correct 232 ms 47876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31956 KB Output is correct
2 Correct 16 ms 31956 KB Output is correct
3 Correct 15 ms 31992 KB Output is correct
4 Correct 17 ms 32084 KB Output is correct
5 Correct 17 ms 32128 KB Output is correct
6 Correct 18 ms 32084 KB Output is correct
7 Correct 17 ms 32024 KB Output is correct
8 Correct 16 ms 32084 KB Output is correct
9 Correct 16 ms 31956 KB Output is correct
10 Correct 19 ms 32148 KB Output is correct
11 Correct 18 ms 32084 KB Output is correct
12 Correct 16 ms 32048 KB Output is correct
13 Correct 16 ms 32084 KB Output is correct
14 Correct 18 ms 32084 KB Output is correct
15 Correct 17 ms 32028 KB Output is correct
16 Correct 17 ms 32084 KB Output is correct
17 Correct 16 ms 32084 KB Output is correct
18 Correct 17 ms 32084 KB Output is correct
19 Execution timed out 2077 ms 32084 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31956 KB Output is correct
2 Correct 15 ms 31956 KB Output is correct
3 Correct 16 ms 31956 KB Output is correct
4 Correct 15 ms 31992 KB Output is correct
5 Correct 17 ms 32084 KB Output is correct
6 Correct 17 ms 32128 KB Output is correct
7 Correct 18 ms 32084 KB Output is correct
8 Correct 17 ms 32024 KB Output is correct
9 Correct 16 ms 32084 KB Output is correct
10 Correct 111 ms 37532 KB Output is correct
11 Correct 128 ms 38768 KB Output is correct
12 Correct 122 ms 38656 KB Output is correct
13 Correct 135 ms 39032 KB Output is correct
14 Correct 105 ms 42924 KB Output is correct
15 Correct 19 ms 32148 KB Output is correct
16 Correct 18 ms 32084 KB Output is correct
17 Correct 16 ms 32048 KB Output is correct
18 Correct 16 ms 32084 KB Output is correct
19 Correct 18 ms 32084 KB Output is correct
20 Correct 17 ms 32028 KB Output is correct
21 Correct 17 ms 32084 KB Output is correct
22 Correct 16 ms 32084 KB Output is correct
23 Correct 17 ms 32084 KB Output is correct
24 Execution timed out 2077 ms 32084 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31956 KB Output is correct
2 Correct 16 ms 31956 KB Output is correct
3 Correct 15 ms 31992 KB Output is correct
4 Correct 17 ms 32084 KB Output is correct
5 Correct 17 ms 32128 KB Output is correct
6 Correct 18 ms 32084 KB Output is correct
7 Correct 17 ms 32024 KB Output is correct
8 Correct 16 ms 32084 KB Output is correct
9 Correct 111 ms 37532 KB Output is correct
10 Correct 128 ms 38768 KB Output is correct
11 Correct 122 ms 38656 KB Output is correct
12 Correct 135 ms 39032 KB Output is correct
13 Correct 105 ms 42924 KB Output is correct
14 Correct 114 ms 37684 KB Output is correct
15 Correct 225 ms 40324 KB Output is correct
16 Correct 222 ms 40284 KB Output is correct
17 Correct 227 ms 40604 KB Output is correct
18 Correct 296 ms 44492 KB Output is correct
19 Correct 238 ms 48008 KB Output is correct
20 Correct 232 ms 48508 KB Output is correct
21 Correct 260 ms 48428 KB Output is correct
22 Correct 233 ms 48396 KB Output is correct
23 Correct 248 ms 48524 KB Output is correct
24 Correct 238 ms 48016 KB Output is correct
25 Correct 246 ms 48408 KB Output is correct
26 Correct 232 ms 47876 KB Output is correct
27 Correct 19 ms 32148 KB Output is correct
28 Correct 18 ms 32084 KB Output is correct
29 Correct 16 ms 32048 KB Output is correct
30 Correct 16 ms 32084 KB Output is correct
31 Correct 18 ms 32084 KB Output is correct
32 Correct 17 ms 32028 KB Output is correct
33 Correct 17 ms 32084 KB Output is correct
34 Correct 16 ms 32084 KB Output is correct
35 Correct 17 ms 32084 KB Output is correct
36 Correct 25 ms 33012 KB Output is correct
37 Correct 127 ms 39060 KB Output is correct
38 Correct 125 ms 39088 KB Output is correct
39 Correct 128 ms 39056 KB Output is correct
40 Correct 126 ms 38996 KB Output is correct
41 Correct 123 ms 38936 KB Output is correct
42 Correct 118 ms 38344 KB Output is correct
43 Correct 130 ms 39080 KB Output is correct
44 Correct 126 ms 39084 KB Output is correct
45 Correct 111 ms 44168 KB Output is correct
46 Correct 138 ms 39084 KB Output is correct
47 Correct 35 ms 33144 KB Output is correct
48 Correct 224 ms 40584 KB Output is correct
49 Correct 229 ms 40620 KB Output is correct
50 Correct 236 ms 40644 KB Output is correct
51 Correct 234 ms 40516 KB Output is correct
52 Correct 224 ms 40280 KB Output is correct
53 Correct 219 ms 39504 KB Output is correct
54 Correct 234 ms 41044 KB Output is correct
55 Correct 229 ms 40624 KB Output is correct
56 Correct 279 ms 44740 KB Output is correct
57 Correct 247 ms 41196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31956 KB Output is correct
2 Correct 15 ms 31956 KB Output is correct
3 Correct 16 ms 31956 KB Output is correct
4 Correct 15 ms 31992 KB Output is correct
5 Correct 17 ms 32084 KB Output is correct
6 Correct 17 ms 32128 KB Output is correct
7 Correct 18 ms 32084 KB Output is correct
8 Correct 17 ms 32024 KB Output is correct
9 Correct 16 ms 32084 KB Output is correct
10 Correct 111 ms 37532 KB Output is correct
11 Correct 128 ms 38768 KB Output is correct
12 Correct 122 ms 38656 KB Output is correct
13 Correct 135 ms 39032 KB Output is correct
14 Correct 105 ms 42924 KB Output is correct
15 Correct 114 ms 37684 KB Output is correct
16 Correct 225 ms 40324 KB Output is correct
17 Correct 222 ms 40284 KB Output is correct
18 Correct 227 ms 40604 KB Output is correct
19 Correct 296 ms 44492 KB Output is correct
20 Correct 238 ms 48008 KB Output is correct
21 Correct 232 ms 48508 KB Output is correct
22 Correct 260 ms 48428 KB Output is correct
23 Correct 233 ms 48396 KB Output is correct
24 Correct 248 ms 48524 KB Output is correct
25 Correct 238 ms 48016 KB Output is correct
26 Correct 246 ms 48408 KB Output is correct
27 Correct 232 ms 47876 KB Output is correct
28 Correct 19 ms 32148 KB Output is correct
29 Correct 18 ms 32084 KB Output is correct
30 Correct 16 ms 32048 KB Output is correct
31 Correct 16 ms 32084 KB Output is correct
32 Correct 18 ms 32084 KB Output is correct
33 Correct 17 ms 32028 KB Output is correct
34 Correct 17 ms 32084 KB Output is correct
35 Correct 16 ms 32084 KB Output is correct
36 Correct 17 ms 32084 KB Output is correct
37 Correct 25 ms 33012 KB Output is correct
38 Correct 127 ms 39060 KB Output is correct
39 Correct 125 ms 39088 KB Output is correct
40 Correct 128 ms 39056 KB Output is correct
41 Correct 126 ms 38996 KB Output is correct
42 Correct 123 ms 38936 KB Output is correct
43 Correct 118 ms 38344 KB Output is correct
44 Correct 130 ms 39080 KB Output is correct
45 Correct 126 ms 39084 KB Output is correct
46 Correct 111 ms 44168 KB Output is correct
47 Correct 138 ms 39084 KB Output is correct
48 Correct 35 ms 33144 KB Output is correct
49 Correct 224 ms 40584 KB Output is correct
50 Correct 229 ms 40620 KB Output is correct
51 Correct 236 ms 40644 KB Output is correct
52 Correct 234 ms 40516 KB Output is correct
53 Correct 224 ms 40280 KB Output is correct
54 Correct 219 ms 39504 KB Output is correct
55 Correct 234 ms 41044 KB Output is correct
56 Correct 229 ms 40624 KB Output is correct
57 Correct 279 ms 44740 KB Output is correct
58 Correct 247 ms 41196 KB Output is correct
59 Correct 90 ms 36420 KB Output is correct
60 Correct 286 ms 40632 KB Output is correct
61 Correct 283 ms 40700 KB Output is correct
62 Correct 295 ms 41120 KB Output is correct
63 Correct 346 ms 45040 KB Output is correct
64 Execution timed out 2077 ms 32084 KB Time limit exceeded
65 Halted 0 ms 0 KB -