Submission #1279379

#TimeUsernameProblemLanguageResultExecution timeMemory
1279379dhuyyyyRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "race.h"
#define fi first
#define se second
#define int long long
using namespace std;

using ii = pair<int,int>;

const int maxn = 2e5+5;
const int maxk = 1e6+5;


int res = 1e18;

int pos[maxk], sub[maxn];

bool num[maxn];

vector <ii> adj[maxn];

void dfs(int u,int p){
    sub[u] = 1;
    for (ii it : adj[u]){
        if (it.fi == p || num[it.fi]) continue;
        dfs(it.fi,u);
        sub[u] += sub[it.fi];
    }
}
int centroid(int u,int p,int n){
    for (ii it : adj[u]){
        if (it.fi == p || num[it.fi]) continue;
        if (sub[it.fi] * 2 > sub[u]) return centroid(it.fi,u,n);
    }
    return u;
}
void getans(int u,int p,int cur,int km,int K){
    if (km > K) return;
    res = min(res,cur + pos[K - km]);
    for (ii it : adj[u]){
        if (it.fi == p || num[it.fi]) continue;
        getans(it.fi,u,cur + 1,km + it.se,K);
    }
    pos[km] = min(pos[km],cur);
}
void solve(int u,int K){
    dfs(u,0);
    int m = sub[u];
    int root = centroid(u,0,m);
    num[root] = 1;
    for (ii it : adj[root]){
        if (num[it.fi]) continue;
        getans(it.fi,root,1,it.se,K);
    }
    for (ii it : adj[u]){
        if (num[it.fi]) continue;
        solve(it.fi,K);
    }
}
int best_path(int N, int K, int H[][2], int L[])
    for (int i = 1; i <= K; i++) pos[i] = 1e18;
    for (int i = 0; i < N - 1; i++){
        H[i][0]++; H[i][1]++;
        adj[H[i][0]].push_back({H[i][1],L[i]});
        adj[H[i][1]].push_back({H[i][0],L[i]});
    }
    solve(1,K);
    return (res <= 0 || res > N ? -1 : res);
}

#ifdef LOCAL
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int N = 11, K = 12;
    int H[10][2] = {{0,1},{0,2},{2,3},{3,4},{4,5},{0,6},{6,7},{6,8},{8,9},{8,10}};
    int L[10] = {3,4,5,4,6,3,2,5,6,7};

    cout << best_path(N, K, H, L) << '\n';

    return 0;
}
#endif // LOCAL

Compilation message (stderr)

race.cpp:61:5: error: expected initializer before 'for'
   61 |     for (int i = 1; i <= K; i++) pos[i] = 1e18;
      |     ^~~
race.cpp:61:21: error: 'i' does not name a type; did you mean 'ii'?
   61 |     for (int i = 1; i <= K; i++) pos[i] = 1e18;
      |                     ^
      |                     ii
race.cpp:61:29: error: 'i' does not name a type; did you mean 'ii'?
   61 |     for (int i = 1; i <= K; i++) pos[i] = 1e18;
      |                             ^
      |                             ii
race.cpp:62:5: error: expected unqualified-id before 'for'
   62 |     for (int i = 0; i < N - 1; i++){
      |     ^~~
race.cpp:62:25: error: 'N' was not declared in this scope
   62 |     for (int i = 0; i < N - 1; i++){
      |                         ^
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:25: error: 'N' was not declared in this scope
race.cpp:62:21: error: 'i' does not name a type; did you mean 'ii'?
   62 |     for (int i = 0; i < N - 1; i++){
      |                     ^
      |                     ii
race.cpp:62:32: error: 'i' does not name a type; did you mean 'ii'?
   62 |     for (int i = 0; i < N - 1; i++){
      |                                ^
      |                                ii
race.cpp:67:10: error: expected constructor, destructor, or type conversion before '(' token
   67 |     solve(1,K);
      |          ^
race.cpp:68:5: error: expected unqualified-id before 'return'
   68 |     return (res <= 0 || res > N ? -1 : res);
      |     ^~~~~~
race.cpp:69:1: error: expected declaration before '}' token
   69 | }
      | ^