Submission #1365658

#TimeUsernameProblemLanguageResultExecution timeMemory
1365658hamza_albrahimRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxn = 200001;

vector<pair<int, int>> adj[mxn];

map<int, int> m[mxn];
dis[mxn];
dep[mxn];
int ans = -1;
int K;

void check(int v, int di, int de){
    int tar = K - di + (2 * dist[v]);
    if(m[v][target] != 0){
        ans = min(ans, m[v][target] + de - (2 * dep[v]));
    }
}

void add(int v, int di, int de){
    if(m[v][di] == 0){
        m[v][di] = de;
    }
    else{
        if(de < m[v][di]){
            m[v][di] = de;
        }
    }
}

void dfs(int v, int p){
    dep[v] = dep[p] + 1;
    int ind = -1;
    for(auto [i, j] : adj[v]){
        if(i != p){
            dist[i] += j;
            dfs(i, v);
            if(ind != -1 || m[i].size() > m[ind].size()){
                ind = i;
            }
        }
    }
    if(m != -1){
        swap(m[ind], m[v]);
    }
    add(v, dis[v], dep[v]);
    for(auto [i, j] : adj[v]){
        if(i != p && i != m){
            for(auto [a, b] : m[i]){
                check(v, a, b);
            }
        }
    }
    for(auto [i, j] : adj[v]){
        if(i != p && i != m){
            for(auto [a, b] : m[i]){
                add(v, a, b);
            }
        }
    }
}

void

int best_path(int n, int k, int h[][2], int l[])
{
    K = k;
    for(int i = 1; i < n; i++){
        adj[h[i][0]].push_back({h[i][1], l[i]});
        adj[h[i][1]].push_back({h[i][0], l[i]});
    }
    dfs(1, 0);
    cout<<ans;

}

Compilation message (stderr)

race.cpp:9:1: error: 'dis' does not name a type
    9 | dis[mxn];
      | ^~~
race.cpp:10:1: error: 'dep' does not name a type
   10 | dep[mxn];
      | ^~~
race.cpp: In function 'void check(int, int, int)':
race.cpp:15:29: error: 'dist' was not declared in this scope; did you mean 'di'?
   15 |     int tar = K - di + (2 * dist[v]);
      |                             ^~~~
      |                             di
race.cpp:16:13: error: 'target' was not declared in this scope
   16 |     if(m[v][target] != 0){
      |             ^~~~~~
race.cpp:17:49: error: 'dep' was not declared in this scope; did you mean 'de'?
   17 |         ans = min(ans, m[v][target] + de - (2 * dep[v]));
      |                                                 ^~~
      |                                                 de
race.cpp: In function 'void dfs(int, int)':
race.cpp:33:5: error: 'dep' was not declared in this scope; did you mean 'dup'?
   33 |     dep[v] = dep[p] + 1;
      |     ^~~
      |     dup
race.cpp:37:13: error: 'dist' was not declared in this scope
   37 |             dist[i] += j;
      |             ^~~~
race.cpp:44:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   44 |     if(m != -1){
      |        ~~^~~~~
race.cpp:47:12: error: 'dis' was not declared in this scope; did you mean 'div'?
   47 |     add(v, dis[v], dep[v]);
      |            ^~~
      |            div
race.cpp:49:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   49 |         if(i != p && i != m){
      |                      ~~^~~~
race.cpp:56:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   56 |         if(i != p && i != m){
      |                      ~~^~~~
race.cpp: At global scope:
race.cpp:64:1: error: two or more data types in declaration of 'best_path'
   64 | void
      | ^~~~