Submission #571307

# Submission time Handle Problem Language Result Execution time Memory
571307 2022-06-01T17:01:43 Z Vanilla Swapping Cities (APIO20_swap) C++17
36 / 100
2000 ms 61744 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 200;
int extra = 1e5 + 1;
const int lg = 29;
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 26 ms 44884 KB Output is correct
2 Correct 25 ms 44900 KB Output is correct
3 Correct 25 ms 44932 KB Output is correct
4 Correct 26 ms 45012 KB Output is correct
5 Correct 27 ms 44952 KB Output is correct
6 Correct 27 ms 44988 KB Output is correct
7 Correct 26 ms 45012 KB Output is correct
8 Correct 27 ms 44980 KB Output is correct
9 Correct 131 ms 50604 KB Output is correct
10 Correct 167 ms 51708 KB Output is correct
11 Correct 155 ms 51652 KB Output is correct
12 Correct 167 ms 51932 KB Output is correct
13 Correct 189 ms 55848 KB Output is correct
14 Correct 135 ms 50624 KB Output is correct
15 Correct 297 ms 53276 KB Output is correct
16 Correct 293 ms 53108 KB Output is correct
17 Correct 322 ms 53572 KB Output is correct
18 Correct 398 ms 57520 KB Output is correct
19 Correct 114 ms 49344 KB Output is correct
20 Correct 363 ms 53624 KB Output is correct
21 Correct 350 ms 53684 KB Output is correct
22 Correct 399 ms 54096 KB Output is correct
23 Correct 479 ms 57876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44884 KB Output is correct
2 Correct 25 ms 44900 KB Output is correct
3 Correct 317 ms 60920 KB Output is correct
4 Correct 323 ms 61608 KB Output is correct
5 Correct 329 ms 61376 KB Output is correct
6 Correct 315 ms 61316 KB Output is correct
7 Correct 332 ms 61448 KB Output is correct
8 Correct 321 ms 60884 KB Output is correct
9 Correct 325 ms 61224 KB Output is correct
10 Correct 340 ms 60804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44884 KB Output is correct
2 Correct 25 ms 44900 KB Output is correct
3 Correct 25 ms 44932 KB Output is correct
4 Correct 26 ms 45012 KB Output is correct
5 Correct 27 ms 44952 KB Output is correct
6 Correct 27 ms 44988 KB Output is correct
7 Correct 26 ms 45012 KB Output is correct
8 Correct 27 ms 44980 KB Output is correct
9 Correct 27 ms 45008 KB Output is correct
10 Correct 25 ms 45060 KB Output is correct
11 Correct 26 ms 44984 KB Output is correct
12 Correct 30 ms 44972 KB Output is correct
13 Correct 29 ms 45064 KB Output is correct
14 Correct 25 ms 45012 KB Output is correct
15 Correct 25 ms 45012 KB Output is correct
16 Correct 26 ms 45032 KB Output is correct
17 Correct 26 ms 45040 KB Output is correct
18 Correct 26 ms 45084 KB Output is correct
19 Execution timed out 2087 ms 45032 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 45008 KB Output is correct
2 Correct 26 ms 44884 KB Output is correct
3 Correct 25 ms 44900 KB Output is correct
4 Correct 25 ms 44932 KB Output is correct
5 Correct 26 ms 45012 KB Output is correct
6 Correct 27 ms 44952 KB Output is correct
7 Correct 27 ms 44988 KB Output is correct
8 Correct 26 ms 45012 KB Output is correct
9 Correct 27 ms 44980 KB Output is correct
10 Correct 131 ms 50604 KB Output is correct
11 Correct 167 ms 51708 KB Output is correct
12 Correct 155 ms 51652 KB Output is correct
13 Correct 167 ms 51932 KB Output is correct
14 Correct 189 ms 55848 KB Output is correct
15 Correct 25 ms 45060 KB Output is correct
16 Correct 26 ms 44984 KB Output is correct
17 Correct 30 ms 44972 KB Output is correct
18 Correct 29 ms 45064 KB Output is correct
19 Correct 25 ms 45012 KB Output is correct
20 Correct 25 ms 45012 KB Output is correct
21 Correct 26 ms 45032 KB Output is correct
22 Correct 26 ms 45040 KB Output is correct
23 Correct 26 ms 45084 KB Output is correct
24 Execution timed out 2087 ms 45032 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 44884 KB Output is correct
2 Correct 25 ms 44900 KB Output is correct
3 Correct 25 ms 44932 KB Output is correct
4 Correct 26 ms 45012 KB Output is correct
5 Correct 27 ms 44952 KB Output is correct
6 Correct 27 ms 44988 KB Output is correct
7 Correct 26 ms 45012 KB Output is correct
8 Correct 27 ms 44980 KB Output is correct
9 Correct 131 ms 50604 KB Output is correct
10 Correct 167 ms 51708 KB Output is correct
11 Correct 155 ms 51652 KB Output is correct
12 Correct 167 ms 51932 KB Output is correct
13 Correct 189 ms 55848 KB Output is correct
14 Correct 135 ms 50624 KB Output is correct
15 Correct 297 ms 53276 KB Output is correct
16 Correct 293 ms 53108 KB Output is correct
17 Correct 322 ms 53572 KB Output is correct
18 Correct 398 ms 57520 KB Output is correct
19 Correct 317 ms 60920 KB Output is correct
20 Correct 323 ms 61608 KB Output is correct
21 Correct 329 ms 61376 KB Output is correct
22 Correct 315 ms 61316 KB Output is correct
23 Correct 332 ms 61448 KB Output is correct
24 Correct 321 ms 60884 KB Output is correct
25 Correct 325 ms 61224 KB Output is correct
26 Correct 340 ms 60804 KB Output is correct
27 Correct 25 ms 45060 KB Output is correct
28 Correct 26 ms 44984 KB Output is correct
29 Correct 30 ms 44972 KB Output is correct
30 Correct 29 ms 45064 KB Output is correct
31 Correct 25 ms 45012 KB Output is correct
32 Correct 25 ms 45012 KB Output is correct
33 Correct 26 ms 45032 KB Output is correct
34 Correct 26 ms 45040 KB Output is correct
35 Correct 26 ms 45084 KB Output is correct
36 Correct 41 ms 46224 KB Output is correct
37 Correct 158 ms 53776 KB Output is correct
38 Correct 182 ms 53808 KB Output is correct
39 Correct 178 ms 53812 KB Output is correct
40 Correct 166 ms 53740 KB Output is correct
41 Correct 160 ms 53620 KB Output is correct
42 Correct 176 ms 52904 KB Output is correct
43 Correct 164 ms 54084 KB Output is correct
44 Correct 164 ms 53764 KB Output is correct
45 Correct 159 ms 58972 KB Output is correct
46 Correct 171 ms 54176 KB Output is correct
47 Correct 51 ms 46468 KB Output is correct
48 Correct 293 ms 57656 KB Output is correct
49 Correct 294 ms 57616 KB Output is correct
50 Correct 295 ms 57728 KB Output is correct
51 Correct 335 ms 57620 KB Output is correct
52 Correct 325 ms 57088 KB Output is correct
53 Correct 296 ms 56184 KB Output is correct
54 Correct 309 ms 58348 KB Output is correct
55 Correct 293 ms 57620 KB Output is correct
56 Correct 414 ms 61744 KB Output is correct
57 Correct 333 ms 58500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 45008 KB Output is correct
2 Correct 26 ms 44884 KB Output is correct
3 Correct 25 ms 44900 KB Output is correct
4 Correct 25 ms 44932 KB Output is correct
5 Correct 26 ms 45012 KB Output is correct
6 Correct 27 ms 44952 KB Output is correct
7 Correct 27 ms 44988 KB Output is correct
8 Correct 26 ms 45012 KB Output is correct
9 Correct 27 ms 44980 KB Output is correct
10 Correct 131 ms 50604 KB Output is correct
11 Correct 167 ms 51708 KB Output is correct
12 Correct 155 ms 51652 KB Output is correct
13 Correct 167 ms 51932 KB Output is correct
14 Correct 189 ms 55848 KB Output is correct
15 Correct 135 ms 50624 KB Output is correct
16 Correct 297 ms 53276 KB Output is correct
17 Correct 293 ms 53108 KB Output is correct
18 Correct 322 ms 53572 KB Output is correct
19 Correct 398 ms 57520 KB Output is correct
20 Correct 317 ms 60920 KB Output is correct
21 Correct 323 ms 61608 KB Output is correct
22 Correct 329 ms 61376 KB Output is correct
23 Correct 315 ms 61316 KB Output is correct
24 Correct 332 ms 61448 KB Output is correct
25 Correct 321 ms 60884 KB Output is correct
26 Correct 325 ms 61224 KB Output is correct
27 Correct 340 ms 60804 KB Output is correct
28 Correct 25 ms 45060 KB Output is correct
29 Correct 26 ms 44984 KB Output is correct
30 Correct 30 ms 44972 KB Output is correct
31 Correct 29 ms 45064 KB Output is correct
32 Correct 25 ms 45012 KB Output is correct
33 Correct 25 ms 45012 KB Output is correct
34 Correct 26 ms 45032 KB Output is correct
35 Correct 26 ms 45040 KB Output is correct
36 Correct 26 ms 45084 KB Output is correct
37 Correct 41 ms 46224 KB Output is correct
38 Correct 158 ms 53776 KB Output is correct
39 Correct 182 ms 53808 KB Output is correct
40 Correct 178 ms 53812 KB Output is correct
41 Correct 166 ms 53740 KB Output is correct
42 Correct 160 ms 53620 KB Output is correct
43 Correct 176 ms 52904 KB Output is correct
44 Correct 164 ms 54084 KB Output is correct
45 Correct 164 ms 53764 KB Output is correct
46 Correct 159 ms 58972 KB Output is correct
47 Correct 171 ms 54176 KB Output is correct
48 Correct 51 ms 46468 KB Output is correct
49 Correct 293 ms 57656 KB Output is correct
50 Correct 294 ms 57616 KB Output is correct
51 Correct 295 ms 57728 KB Output is correct
52 Correct 335 ms 57620 KB Output is correct
53 Correct 325 ms 57088 KB Output is correct
54 Correct 296 ms 56184 KB Output is correct
55 Correct 309 ms 58348 KB Output is correct
56 Correct 293 ms 57620 KB Output is correct
57 Correct 414 ms 61744 KB Output is correct
58 Correct 333 ms 58500 KB Output is correct
59 Correct 114 ms 49344 KB Output is correct
60 Correct 363 ms 53624 KB Output is correct
61 Correct 350 ms 53684 KB Output is correct
62 Correct 399 ms 54096 KB Output is correct
63 Correct 479 ms 57876 KB Output is correct
64 Execution timed out 2087 ms 45032 KB Time limit exceeded
65 Halted 0 ms 0 KB -