#include <bits/stdc++.h>
#include "factories.h"
#define ff first
#define ss second
using namespace std;
typedef long long ll;
const ll N = 5e5 + 10;
const ll M = 2e6 + 20;
const ll inf = 1e17;
int n,t[N],p[N];
ll d[N],q[N];
vector<pair<int,ll>> g[N];
deque<ll> s[N];
void dfs(int v,int f){
t[v] = 1;
for(auto [u,w] : g[v]){
if(u == f) continue;
d[]
dfs(u,v);
t[v] += t[u];
}
}
int find(int v,int f,int tm){
for(auto [u,w] : g[v]){
if(u == f) continue;
if(t[u]*2 > tm) return find(u,v,tm);
}
return v;
}
void gfs(int v,int f){
s[v].push_top(d[v]);
for(auto [u,w] : g[v]){
if(u == f) continue;
d[u] = d[v] + w;
gfs(u,v);
}
}
void build(int v,int f){
dfs(v,f);
int c = find(v,f,sz[v]);
d[v] = 0, p[c] = f;
gfs(v,f);
for(auto [u,w] : g[c]){
if(u == f) continue;
build(u,c);
}
}
void Init(int N, int A[], int B[], int D[]){
n = N;
for(int i = 0; i < n; ++i){
g[A[i]].push_back({B[i],(ll) D[i]});
g[B[i]].push_back({A[i],(ll) D[i]});
}
build(0,-1);
}
long long Query(int S, int X[], int T, int Y[]){
for(int i = 0; i < S; ++i){
int aux = x[i], id = 0;
while(aux != -1){
q[aux] = min(q[aux],s[x[i]][id]);
aux = p[aux], id++;
}
}
ll ans = inf;
for(int i = 0; i < T; ++i){
int aux = y[i], id = 0;
while(aux != -1){
ans = min(ans,q[aux]+s[y[i]][id]);
aux = p[aux], id++;
}
}
for(int i = 0; i < S; ++i){
int aux = x[i];
while(aux != -1) q[aux] = inf, aux = p[aux];
}
return ans;
}
Compilation message
factories.cpp: In function 'void dfs(int, int)':
factories.cpp:21:5: error: expected primary-expression before ']' token
21 | d[]
| ^
factories.cpp: In function 'void gfs(int, int)':
factories.cpp:36:7: error: 'class std::deque<long long int>' has no member named 'push_top'; did you mean 'push_front'?
36 | s[v].push_top(d[v]);
| ^~~~~~~~
| push_front
factories.cpp: In function 'void build(int, int)':
factories.cpp:46:19: error: 'sz' was not declared in this scope; did you mean 's'?
46 | int c = find(v,f,sz[v]);
| ^~
| s
factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:66:13: error: 'x' was not declared in this scope
66 | int aux = x[i], id = 0;
| ^
factories.cpp:68:32: error: 'id' was not declared in this scope; did you mean 'i'?
68 | q[aux] = min(q[aux],s[x[i]][id]);
| ^~
| i
factories.cpp:74:13: error: 'y' was not declared in this scope
74 | int aux = y[i], id = 0;
| ^
factories.cpp:76:33: error: 'id' was not declared in this scope; did you mean 'i'?
76 | ans = min(ans,q[aux]+s[y[i]][id]);
| ^~
| i
factories.cpp:81:13: error: 'x' was not declared in this scope
81 | int aux = x[i];
| ^