Submission #645453

# Submission time Handle Problem Language Result Execution time Memory
645453 2022-09-27T07:00:08 Z karrigan Factories (JOI14_factories) C++14
Compilation error
0 ms 0 KB
#include "factories.h"
#include<iostream>
#include<algorithm>
using namespace std;
const long long mx=1e15;
struct edg{
int v;
long long w;
};
vector<edg>g[500001];
long long dis[500001];
int dep[500001];
int st[500001][21];
int sub[500001];
int use[500001];
void dfs(int u,int par){
    for (auto v:g[u]){
        if (v.v==par)continue;
        dis[v.v]=v.w+dis[u];
        dep[v.v]=dep[u]+1;
        st[v.v][0]=u;
        dfs(v.v,u);
    }
}
inline int lca(int u,int v){
if (dep[u]<dep[v])swap(u,v);
int k=dep[u]-dep[v];
for (int i=20;i>=0;i--){
    if (k>>i&1){
        u=st[u][i];
    }
}
if (u==v)return u;
for (int i=20;i>=0;i--){
    if (st[u][i]==0||st[v][i]==0)continue;
    if (st[u][i]!=st[v][i]){
        u=st[u][i];
        v=st[v][i];
    }
}
return st[u][0];
}
inline long long cal(int u,int v){
return dis[u]+dis[v]-2*dis[lca(u,v)];
}
inline int dfs2(int u,int par){
    sub[u]=1;
    for (auto v:g[u]){
        int lm=v.v;
        if (use[lm]||lm==par)continue;
        dfs2(lm,u);
        sub[u]+=sub[lm];
    }
    return sub[u];
}
inline int centroid(int u,int p,int sz){
    for (auto v:g[u]){
        if (use[v.v]||v.v==p)continue;
        if (sub[v.v]*2>sz)return centroid(v.v,u,sz);
    }
    return u;
}
int par[500001];
long long mxx[500001];
int decompose(int u,int p){
int sz=dfs2(u,0);
int cen=centroid(u,0,sz);
use[cen]=1;
if (p!=0){
    par[cen]=p;
}
for (auto v:g[cen]){
    if (use[v.v])continue;
    decompose(v.v,cen);
}
return cen;
}
void Init(int n,int a[],int b[],int d[]){
for (int i=0;i<n-1;i++){
    a[i]++;
    b[i]++;
    g[a[i]].push_back({b[i],d[i]});
    g[b[i]].push_back({a[i],d[i]});
}
dfs(1,0);
for (int i=1;i<=20;i++){
    for (int j=1;j<=n;j++){
        st[j][i]=st[st[j][i-1]][i-1];
    }
}
for (int i=1;i<=n;i++){
    mxx[i]=1e17;
}
decompose(1,0);
}
inline void update(int u,int pos){
if (pos==0)return;
mxx[pos]=min(mxx[pos],cal(u,pos));
update(u,par[pos]);
}
inline void res(int u,int pos){
if (pos==0)return;
mxx[pos]=1e17;
res(u,par[pos]);
}
inline long long get(int u,int pos){
long long ans=1e17;
if (pos==0)return ans;
ans=min(ans,cal(u,pos)+mxx[pos]);
ans=min(ans,get(u,par[pos]));
return ans;
}
long long Query(int s,int x[],int t,int y[]){
for (int i=0;i<t;i++){
    update(y[i]+1,y[i]+1);
}
long long ans=1e17;
for (int i=0;i<s;i++){
    ans=min(ans,get(x[i]+1,x[i]+1));
}
for (int i=0;i<t;i++){
    res(y[i]+1,y[i]+1);
}
return ans;
}

Compilation message

factories.cpp:10:1: error: 'vector' does not name a type
   10 | vector<edg>g[500001];
      | ^~~~~~
factories.cpp: In function 'void dfs(int, int)':
factories.cpp:17:17: error: 'g' was not declared in this scope
   17 |     for (auto v:g[u]){
      |                 ^
factories.cpp: In function 'int dfs2(int, int)':
factories.cpp:48:17: error: 'g' was not declared in this scope
   48 |     for (auto v:g[u]){
      |                 ^
factories.cpp: In function 'int centroid(int, int, int)':
factories.cpp:57:17: error: 'g' was not declared in this scope
   57 |     for (auto v:g[u]){
      |                 ^
factories.cpp: In function 'int decompose(int, int)':
factories.cpp:72:13: error: 'g' was not declared in this scope
   72 | for (auto v:g[cen]){
      |             ^
factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:82:5: error: 'g' was not declared in this scope
   82 |     g[a[i]].push_back({b[i],d[i]});
      |     ^