Submission #1263849

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

//#define ll long long
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define sz(x)(ll) x.size()
#define ins insert
#define speed ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pf push_front
#define pb push_back
#define all(x) x.begin(), x.end()
#define pii pair < ll, int >
#define pll pair < ll, ll >
#define vi vector < ll >
#define vll vector < long long >
#define vpii vector < pair < ll, int >>
#define vpll vector < pair < long long, long long >>
#define mem(x, val) memset(x, val, sizeof x)
#define debug cerr << "OK\n";

mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());

const ll inf = 1e9 + 100;
const ll INF = (ll)1e18;
const ll INF1 = (ll)1e14 + 1;
const ll MAXN = (int)5e5 + 5;
const ll mod = (ll)1e9 + 7;
const ll mod1 = (ll)1e9 + 9;
const ll MAX = (ll)1e6 + 5;
//const ll P = 331;
//const ll K = 17;

ll binpow(ll a, ll n) {
    if (n == 0) return 1;
    if (n == 1) return (a % mod);
    ll r = binpow(a, n / 2);
    if (n & 1) return (((r * r) % mod) * a) % mod;
    return (r * r) % mod;
}

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

ll add(ll a, ll b) {
    return (((a + b) % mod) + mod) % mod;
}

ll mul(ll a, ll b) {
    return (a * b) % mod;
}

ll n, k;
map<ll, ll> ma[MAXN]; 
ll sum[MAXN], d[MAXN];
vector<pii> G[MAXN];
vector<ll> g[MAXN];
int ans = inf;

void prec(ll v, int par = -1) {
    for (auto [u, w] : G[v]) {
        if (u == par) continue;
        g[v].pb(u);
        sum[u] = sum[v] + w;
        d[u] = d[v] + 1;
        prec(u, v);
    }
}

void dfs(ll v) {
    for (ll u : g[v]) {
        dfs(u);
    }
    ma[v][sum[v]] = d[v];
    for (ll i = 1; i < sz(g[v]); i++) {
        ll x = g[v][i - 1], y = g[v][i];
        if (sz(ma[x]) > sz(ma[y])) swap(ma[x], ma[y]);
        for (auto [sx, dx] : ma[x]) {
            ll sy = k + 2 * sum[v] - sx;
            if (ma[y].count(sy)) {
                ll dy = ma[y][sy];
                ans = min(ans, dx + dy - 2 * d[v]);
            }
        }
        for (auto [sx, dx] : ma[x]) {
            if (!ma[y].count(sx)) {
                ma[y][sx] = dx;
                continue;
            }
            ma[y][sx] = min(ma[y][sx], dx);
        }
    }
    if (sz(g[v])) {
        ll y = g[v].back();
        ll sy = k + sum[v];
        if (ma[y].count(sy)) {
            ll dy = ma[y][sy];
            ans = min(ans, dy - d[v]);
        }
        swap(ma[v], ma[y]);
        if (!ma[v].count(sum[v])) {
            ma[v][sum[v]] = d[v];
        } else {
            ma[v][sum[v]] = min(ma[v][sum[v]], d[v]);
        }
    }
}


int best_path(int N, int K, int H[][2], int L[]) {
    n = N, k = K;
    for (ll i = 0; i < N - 1; i++) {
        G[H[i][0]].pb({H[i][1], L[i]});
        G[H[i][1]].pb({H[i][0], L[i]});
    }
    prec(0);
    dfs(0);
    return ans;
}

Compilation message (stderr)

race.cpp: In function 'void dfs(ll)':
race.cpp:92:26: error: no matching function for call to 'min(int&, std::tuple_element<1, std::pair<const long long int, long long int> >::type)'
   92 |                 ans = min(ans, dx + dy - 2 * d[v]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
race.cpp:92:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::tuple_element<1, std::pair<const long long int, long long int> >::type' {aka 'long long int'})
   92 |                 ans = min(ans, dx + dy - 2 * d[v]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
race.cpp:92:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::tuple_element<1, std::pair<const long long int, long long int> >::type' {aka 'long long int'})
   92 |                 ans = min(ans, dx + dy - 2 * d[v]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
race.cpp:92:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   92 |                 ans = min(ans, dx + dy - 2 * d[v]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
race.cpp:92:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   92 |                 ans = min(ans, dx + dy - 2 * d[v]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:108:22: error: no matching function for call to 'min(int&, ll)'
  108 |             ans = min(ans, dy - d[v]);
      |                   ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
race.cpp:108:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  108 |             ans = min(ans, dy - d[v]);
      |                   ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
race.cpp:108:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  108 |             ans = min(ans, dy - d[v]);
      |                   ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
race.cpp:108:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  108 |             ans = min(ans, dy - d[v]);
      |                   ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
race.cpp:108:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  108 |             ans = min(ans, dy - d[v]);
      |                   ~~~^~~~~~~~~~~~~~~~
race.cpp: In function 'void setIO(std::string)':
race.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~