Submission #1091807

# Submission time Handle Problem Language Result Execution time Memory
1091807 2024-09-22T08:02:07 Z Luca1234 Race (IOI11_race) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax=2e5+3;
vector <pair <int, int> > v[nmax];
map <int, int> m[nmax];
int k, ans=nmax;

void dfs(int nod, int parent, int d, int h)
{
    m[nod][d]=h;
    for(auto [i, cost]:v[nod])
    {
        if(i!=parent)
        {
            dfs(i, nod, d+cost, h+1);
            if(m[i].size()>m[nod].size) swap(m[i], m[nod]);
            for(auto [dist, he]:m[i])
            {
                int caut=k-(dist+2*d);
                if(m[nod].count(caut))
                {
                    ans=min(ans, he+m[nod][caut]-2*h);
                }
            }
            for(auto [dist, he]:m[i])
            {
                if(m[nod].count(dist))
                {
                    m[nod][dist]=min(m[nod][dist], he);
                }
                else m[nod][dist]=he;
            }
        }
    }
}

long long best_path(int n, int k, int h[][2], int l[])
{
    ::k=k;
    for(int i=0; i<n-1; i++)
    {
        int a=h[i][0], b=h[i][1];
        v[a].push_back({b l[i]});
        v[b].push_back({a, l[i]});
    }
    dfs(0, -1, 0, 1);
    if(ans==nmax) return -1;
    return ans;
}

Compilation message

race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:18:35: error: invalid use of member function 'std::map<_Key, _Tp, _Compare, _Alloc>::size_type std::map<_Key, _Tp, _Compare, _Alloc>::size() const [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::size_type = long unsigned int]' (did you forget the '()' ?)
   18 |             if(m[i].size()>m[nod].size) swap(m[i], m[nod]);
      |                            ~~~~~~~^~~~
      |                                       ()
race.cpp: In function 'long long int best_path(int, int, int (*)[2], int*)':
race.cpp:45:27: error: expected '}' before 'l'
   45 |         v[a].push_back({b l[i]});
      |                        ~  ^
race.cpp:45:26: error: expected ')' before 'l'
   45 |         v[a].push_back({b l[i]});
      |                       ~  ^~
      |                          )
race.cpp:45:32: error: expected primary-expression before ')' token
   45 |         v[a].push_back({b l[i]});
      |                                ^
race.cpp:46:11: error: 'b' was not declared in this scope
   46 |         v[b].push_back({a, l[i]});
      |           ^
race.cpp:46:25: error: 'a' was not declared in this scope
   46 |         v[b].push_back({a, l[i]});
      |                         ^
race.cpp:46:30: error: 'i' was not declared in this scope
   46 |         v[b].push_back({a, l[i]});
      |                              ^
race.cpp:47:5: warning: no return statement in function returning non-void [-Wreturn-type]
   47 |     }
      |     ^
race.cpp: At global scope:
race.cpp:48:8: error: expected constructor, destructor, or type conversion before '(' token
   48 |     dfs(0, -1, 0, 1);
      |        ^
race.cpp:49:5: error: expected unqualified-id before 'if'
   49 |     if(ans==nmax) return -1;
      |     ^~
race.cpp:50:5: error: expected unqualified-id before 'return'
   50 |     return ans;
      |     ^~~~~~
race.cpp:51:1: error: expected declaration before '}' token
   51 | }
      | ^