Submission #1046227

#TimeUsernameProblemLanguageResultExecution timeMemory
1046227I_FloPPed21Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
map<int,long long> mp[200005] ;
vector<pair<int,int>> adj[200005];
int h[200005][2], target = 0,sum[200005],height[200005],ans = 1e9,n,k;

void precomp(int nod, int p, int hd)
{
    height[nod] = hd ;
    for ( auto u : adj[nod] )
    {
        if ( u.first != p )
        {
            sum[u.first] += sum[nod]    + u.second;
            precomp(u.first,nod,hd + 1);
        }
    }
}

void small(int nod,int p )
{
    mp[nod][sum[nod]] = height[nod];
    long long real_target = target + 2 * sum[nod];
    for ( auto u : adj[nod] )
    {
        if ( u.first != p )
        {
            small(u.first,nod);
        }
    }

    for ( auto u : adj[nod] )
    {
        if( u.first != p )
        {
            if( mp[u.first].size() > mp[nod].size())
                swap(mp[nod],mp[u.first]);

            for ( auto k : mp[u.first] )
            {
                long long real = real_target - k.first ;

                /* if( nod == 6 && u.first == 8 )
                 {
                     cout << real << '\n';
                 }*/
                if ( mp[nod].find(real) != mp[nod].end())
                {
                    //cout << nod << " " << u.first << " " << k.first << " " << k.second << '\n';
                    ans = min ( long(ans), long(k.second + mp[nod][real] - 2 * height[nod]));
                }


            }

            for ( auto k : mp[u.first])
                {if( mp[nod][k.first] == 0 )
                    mp[nod][k.first] = k .second;
                else
                    mp[nod][k.first] = min(mp[nod][k.first],k.second);

            }
        }
    }

    /*if( nod == 6)
    {
        cout << mp[nod][real_target]<< '\n';
    }*/
}
int best_path(int n, int k, int h[][2], int costs [] )
{
    if( k == 1 )
    {
        return 0 ;
    }
    target =k ;

    for ( int i = 1; i < n ; i ++ )
    {
        adj[h[i][1]].push_back({h[i][0],costs[i]});
        adj[h[i][0]].push_back({h[i][1],costs[i]});
    }


    precomp(0,-1,1);
    small(0,-1);
   return ans == (ll)1e9 ? -1:ans;
}
int v[200005];
 /*int main()
{
    cin >> n >> k;
    for ( int i = 1; i < n ; i ++ )
    {
        cin >> h[i][0] >> h[i][1] >> v[i] ;
    }

    cout << best_path(n,k,h,v);

    return 0;
}*/

Compilation message (stderr)

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:89:19: error: 'll' was not declared in this scope
   89 |    return ans == (ll)1e9 ? -1:ans;
      |                   ^~
race.cpp:89:22: error: expected ';' before numeric constant
   89 |    return ans == (ll)1e9 ? -1:ans;
      |                      ^~~
      |                      ;
race.cpp:89:34: warning: second operand of conditional expression has no effect [-Wunused-value]
   89 |    return ans == (ll)1e9 ? -1:ans;
      |                                  ^
race.cpp:89:34: warning: third operand of conditional expression has no effect [-Wunused-value]