Submission #780035

# Submission time Handle Problem Language Result Execution time Memory
780035 2023-07-12T05:54:03 Z cheat_when_I_was_young Factories (JOI14_factories) C++17
Compilation error
0 ms 0 KB
#include "factories.h"

const int NM = 5e5 + 5;

int in[NM], d[NM], h[NM];
vector<int> tour;
vector<pair<int,int>> adj[NM];

void dfs(int u, int par) {
    in[u] = tour.size();
    tour.push_back(u);
    for (auto &vv: adj[u]) {
        int v = vv.first, w = vv.second;
        if (v == par) continue;
        d[v] = d[u] + w;
        h[v] = h[u] + 1;
        dfs(v, u);
    }
    tour.push_back(u);
}

const int LG = __lg(NM) + 1;

pair<int,int> ST[LG][NM];

void build() {
    for (int i = 0; i < tour.size(); ++i)
        ST[0][i] = {h[tour[i]], tour[i]};
    for (int j = 1; j < LG; ++j)
        for (int i = 0; i + (1<<j) - 1 < tour.size(); ++i)
            ST[j][i] = min(ST[j-1][i], ST[j-1][i + (1<<(j-1))]);
}

int lca(int l, int r) {
    int k = __lg(r - l + 1);
    return min(ST[k][l], ST[k][r - (1<<k) + 1]).second;
}

void Init(int N, int A[], int B[], int D[]) {
    for (int i = 0; i < N-1; ++i) {
        adj[A[i]].push_back({B[i], D[i]});
        adj[B[i]].push_back({A[i], D[i]});
    }
    dfs(1, 1);
    build();
}

long long Query(int S, int X[], int T, int Y[]) {
    return 0;
}

Compilation message

factories.cpp:6:1: error: 'vector' does not name a type
    6 | vector<int> tour;
      | ^~~~~~
factories.cpp:7:1: error: 'vector' does not name a type
    7 | vector<pair<int,int>> adj[NM];
      | ^~~~~~
factories.cpp: In function 'void dfs(int, int)':
factories.cpp:10:13: error: 'tour' was not declared in this scope
   10 |     in[u] = tour.size();
      |             ^~~~
factories.cpp:12:20: error: 'adj' was not declared in this scope
   12 |     for (auto &vv: adj[u]) {
      |                    ^~~
factories.cpp:15:23: error: 'w' was not declared in this scope
   15 |         d[v] = d[u] + w;
      |                       ^
factories.cpp: At global scope:
factories.cpp:22:16: error: '__lg' was not declared in this scope
   22 | const int LG = __lg(NM) + 1;
      |                ^~~~
factories.cpp:24:1: error: 'pair' does not name a type
   24 | pair<int,int> ST[LG][NM];
      | ^~~~
factories.cpp: In function 'void build()':
factories.cpp:27:25: error: 'tour' was not declared in this scope
   27 |     for (int i = 0; i < tour.size(); ++i)
      |                         ^~~~
factories.cpp:28:9: error: 'ST' was not declared in this scope
   28 |         ST[0][i] = {h[tour[i]], tour[i]};
      |         ^~
factories.cpp:30:42: error: 'tour' was not declared in this scope
   30 |         for (int i = 0; i + (1<<j) - 1 < tour.size(); ++i)
      |                                          ^~~~
factories.cpp:31:13: error: 'ST' was not declared in this scope
   31 |             ST[j][i] = min(ST[j-1][i], ST[j-1][i + (1<<(j-1))]);
      |             ^~
factories.cpp:31:24: error: 'min' was not declared in this scope; did you mean 'in'?
   31 |             ST[j][i] = min(ST[j-1][i], ST[j-1][i + (1<<(j-1))]);
      |                        ^~~
      |                        in
factories.cpp: In function 'int lca(int, int)':
factories.cpp:35:13: error: '__lg' was not declared in this scope
   35 |     int k = __lg(r - l + 1);
      |             ^~~~
factories.cpp:36:16: error: 'ST' was not declared in this scope
   36 |     return min(ST[k][l], ST[k][r - (1<<k) + 1]).second;
      |                ^~
factories.cpp:36:12: error: 'min' was not declared in this scope; did you mean 'in'?
   36 |     return min(ST[k][l], ST[k][r - (1<<k) + 1]).second;
      |            ^~~
      |            in
factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:41:9: error: 'adj' was not declared in this scope
   41 |         adj[A[i]].push_back({B[i], D[i]});
      |         ^~~