Submission #1343541

#TimeUsernameProblemLanguageResultExecution timeMemory
1343541SemicolonRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
/**
 *     Author: Lưu Diệp Thành (Save Diệp Thành)
 *     Le Hong Phong High School for the Gifted (i2528)
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define ll long long
#define ushort unsigned short
#define FOR(i,l,r) for(int i = (l), _r = (r); i <= _r; i++)
#define FORN(i,r,l) for(int i = (r), _l = (l); i >= _l; i--)
#define endl '\n'
#define sz(x) (int)x.size()
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define MASK(x) (1LL << (x))
#define BIT(x,i) (((x) >> (i)) & 1)
#define ins insert
#define segleft (id<<1)
#define segright (id<<1|1)
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
const int MOD = 1e9+7;

const int N = 2e5+5;
vector<pair<int,int>> edge[N];
map<int,int> mp[N];
int dist[N], high[N];
int node, s;
int ans = LLONG_MAX;

void dfs(int u, int p) {
    high[u] = high[p] + 1;
    for(auto[v,w] : edge[u]) if (v!=p) {
        dist[v] = dist[u] + w;
        dfs(v,u);
    }
}

void SmallToLarge(int u, int p) {
    for(auto[v,w] : edge[u]) if (v!=p) {
        SmallToLarge(v, u);

        if (sz(mp[u]) < sz(mp[v])) swap(mp[u], mp[v]);

        for(pair<int,int> cur : mp[v]) {
            int d1 = cur.fi, len = cur.se;
            if (s - 2*dist[u] - d1 >= 0) {
                int d2 = s - 2*dist[u] - d1;
                if (mp[u].count(d2)) {
                    ans = min(ans, len + mp[u][d2] - 2*high[u]);
                }
            }
        }

        if (s - 2*dist[u]) {
            int d2 = s - 2*dist[u];
            if (mp[u].count(d2)) {
                ans = min(ans, mp[u][d2] - high[u]);
            }
        }

        for(pair<int,int> cur : mp[v]) {
            if (mp[u].count(cur.fi)) {
                mp[u][cur.fi] = min(mp[u][cur.fi], cur.se);
            } else {
                mp[u][cur.fi] = cur.se;
            }
        }
    }
    if (mp[u].count(dist[u])) {
        mp[u][dist[u]] = min(mp[u][dist[u]], high[u]);
    } else {
        mp[u][dist[u]] = high[u];
    }
}

int best_path(int n, int k, h[][2], l[]) {
    node = n;
    s = k;

    FOR(i, 0, n-1) {
        int u = h[i][0], v = h[i][1], w = l[i];
        u++; v++;
        edge[u].pb({v, w});
        edge[v].pb({u, w});
    }

    dfs(1, 0);
    SmallToLarge(1, 0);

    return (ans == LLONG_MAX ? -1 : ans);
}

Compilation message (stderr)

race.cpp:79:29: error: 'h' has not been declared
   79 | int best_path(int n, int k, h[][2], l[]) {
      |                             ^
race.cpp:79:37: error: 'l' has not been declared
   79 | int best_path(int n, int k, h[][2], l[]) {
      |                                     ^
race.cpp: In function 'long long int best_path(long long int, long long int, int (*)[2], int*)':
race.cpp:84:17: error: 'h' was not declared in this scope
   84 |         int u = h[i][0], v = h[i][1], w = l[i];
      |                 ^
race.cpp:85:14: error: 'v' was not declared in this scope
   85 |         u++; v++;
      |              ^
race.cpp:86:24: error: 'w' was not declared in this scope
   86 |         edge[u].pb({v, w});
      |                        ^
race.cpp:86:19: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
   86 |         edge[u].pb({v, w});
      |         ~~~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from race.cpp:5:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~