Submission #1282917

#TimeUsernameProblemLanguageResultExecution timeMemory
1282917mlecioRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
int n,k,
vector<pair<int,int>>Ver[200'005];
int naj[1'000'006];
bool kil[200'005];
vector<int>czy;
int sz[200'005];
int ans=1e9+1;
int dfs_sz(int u,int v){
sz[u]=1;

void upd(int u,bool cz,int suma,int ile,int v){
if(suma>k)return;
czy.emplace_back(suma);
if(cz){
    ans=min(res,naj[k-suma]+ile);
}
else {
    naj[suma]=min(naj[suma],ile);
}
for(auto &x:Ver[u]){
    if(!kil[x.first] &&x.first!=v){
        upd(x,cz,suma+x.second,ile+1,u);
    }
}
}

for(auto &x:Ver[u]){
    if(x.first!=v && !kill[x.first]){
        sz[u]+=dfs_sz(x,u);
    }
}
return sz[u];
}

int cent(int u,int v,int nk){
    for(auto &x:Ver[u]){
        if(x.first!=v && !kill[x.first] && 2*sz[x]>nk)
            return cent(x,u,nk);
    }
    return u;
}

void centroid(int u){
    int root=cent(u,-1,dfs_sz(u,-1));
    kil[root]=1;
    czy.clear();
    for(auto &x:Ver[cent]){
        upd(x.first,1,x.second,1,-1);
        upd(x.first,0,x.second,1,-1);
    }
    for(auto &x:czy){
        naj[x]=1e9+2137;
    }
    for(auto &x:Ver[root]){
        if(!kil[x])
            centroid(x);
    }
}

int best_path(int N,int K,int V[][2],int len[]){
n=N;
k=K;
for(int i=0;i<k-1;i++){
    Ver[V[i][0]+1].push_back({V[i][1]+1,len[i]});
    Ver[V[i][1]+1].push_back({V[i][0]+1,len[i]});
}
memset(naj,1e9+2137,sizeof naj);
naj[0]=0;
centroid(0);
return (ans==1e9+1 ? -1 : ans);
}

Compilation message (stderr)

race.cpp:4:22: error: invalid declarator before 'Ver'
    4 | vector<pair<int,int>>Ver[200'005];
      |                      ^~~
race.cpp: In function 'int dfs_sz(int, int)':
race.cpp:13:47: error: a function-definition is not allowed here before '{' token
   13 | void upd(int u,bool cz,int suma,int ile,int v){
      |                                               ^
race.cpp:29:13: error: 'Ver' was not declared in this scope
   29 | for(auto &x:Ver[u]){
      |             ^~~
race.cpp: In function 'int cent(int, int, int)':
race.cpp:38:17: error: 'Ver' was not declared in this scope
   38 |     for(auto &x:Ver[u]){
      |                 ^~~
race.cpp: In function 'void centroid(int)':
race.cpp:49:17: error: 'Ver' was not declared in this scope
   49 |     for(auto &x:Ver[cent]){
      |                 ^~~
race.cpp:50:9: error: 'upd' was not declared in this scope
   50 |         upd(x.first,1,x.second,1,-1);
      |         ^~~
race.cpp:56:17: error: 'Ver' was not declared in this scope
   56 |     for(auto &x:Ver[root]){
      |                 ^~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:66:5: error: 'Ver' was not declared in this scope
   66 |     Ver[V[i][0]+1].push_back({V[i][1]+1,len[i]});
      |     ^~~