Submission #104356

# Submission time Handle Problem Language Result Execution time Memory
104356 2019-04-05T15:15:24 Z nvmdava Race (IOI11_race) C++17
Compilation error
0 ms 0 KB
#include "race.h"
#include <bits/stdc++.h>
#define N 200005
#define pb push_back
#define pii pair<int, int>
bool blocked[N];
int n, s;

vector<pii> adj[N];
int sz[N];
int sumsz;
int len[5 * N];
void get_size(int v, int p){
    sz[v] = 1;
    len[v] = 0x3f3f3f3f;
    for(auto& c : adj[v]){
        if(c.ff == p || blocked[c.ff])
            continue;
        get_size(c.ff, v);
        sz[v] += sz[c.ff];
    }
}

int get_centroid(int v, int p){
    for(auto& c : adj[v]){
        if(c.ff == p || blocked[c.ff])
            continue;
        if(sz[c.ff] >= sumsz / 2)
            return get_centroid(c.ff, v);
    }
    return v;
}
int ans = N;
queue<pii> q;
void dfs(int v, int p, int l, int cnt){
    ans = min(ans, len[s - l] + cnt);
    q.push({l, cnt});
    cnt++;
    for(auto& c : adj[v]){
        if(c.ff == p || blocked[c])
            continue;
        dfs(c.ff, v, l + c.ss, cnt);
    }
    if(p == -1){
        while(!q.empty()){
            len[q.top().ff] = min(len[q.top().ff], q.top().ss);
            q.pop();
        }
    }
}

void decomp(int v){
    get_size(v, -1);
    v = get_centroid(v, -1);
    blocked[v] = 1;
    for(auto &c : adj[v]){
        if(blocked[c.ff])
            continue;
        dfs(c.ff, -1, 0, 0);
    }

    for(auto &c : adj[v]){
        if(blocked[c.ff])
            continue;
        decomp(c.ff);
    }
}


int best_path(int n, int s, int h[][2], int l[]){
    ::n = n;
    ::s = s;
    for(int i = 0; i < n - 1; i++){
        adj[h[i][0]].pb({h[i][1], l[i]});
        adj[h[i][1]].pb({h[i][0], l[i]});
    }

    decomp(1);
    return (ans == N ? -1 : ans);
}

Compilation message

race.cpp:9:1: error: 'vector' does not name a type; did you mean 'wctob'?
 vector<pii> adj[N];
 ^~~~~~
 wctob
race.cpp: In function 'void get_size(int, int)':
race.cpp:16:19: error: 'adj' was not declared in this scope
     for(auto& c : adj[v]){
                   ^~~
race.cpp: In function 'int get_centroid(int, int)':
race.cpp:25:19: error: 'adj' was not declared in this scope
     for(auto& c : adj[v]){
                   ^~~
race.cpp: At global scope:
race.cpp:34:1: error: 'queue' does not name a type; did you mean 'sigqueue'?
 queue<pii> q;
 ^~~~~
 sigqueue
race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:36:11: error: 'min' was not declared in this scope
     ans = min(ans, len[s - l] + cnt);
           ^~~
race.cpp:36:11: note: suggested alternative:
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   'std::min'
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
race.cpp:37:5: error: 'q' was not declared in this scope
     q.push({l, cnt});
     ^
race.cpp:39:19: error: 'adj' was not declared in this scope
     for(auto& c : adj[v]){
                   ^~~
race.cpp: In function 'void decomp(int)':
race.cpp:56:19: error: 'adj' was not declared in this scope
     for(auto &c : adj[v]){
                   ^~~
race.cpp:62:19: error: 'adj' was not declared in this scope
     for(auto &c : adj[v]){
                   ^~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:74:9: error: 'adj' was not declared in this scope
         adj[h[i][0]].pb({h[i][1], l[i]});
         ^~~