Submission #42561

# Submission time Handle Problem Language Result Execution time Memory
42561 2018-02-28T06:17:18 Z comfile Race (IOI11_race) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long int ll;
using namespace std;
const int N = 200010;
int n,k,sz[N],dead[N],ans;
vector<pii> g[N];
void get_sz(int cur,int prev){
    sz[cur] = 1;
    for(auto &x : g[cur]) if(!dead[x.first] && x.first!=prev){
        get_sz(x.first,cur);
      sz[cur] += sz[x.first];
    }
}
int dfs(int cur,int prev,int tot){
    for(auto &x : g[cur]) if(!dead[x.first] && x.first!=prev){
        if(sz[x.first]>(tot/2)) return dfs(x.first,cur,tot);
    }
    return cur;
}
int one(int start){
    get_sz(start,-1);
    return dfs(start,-1,sz[start]);
}
void rec(int cur){
    int c = one(cur);
    dead[c] = 1;
    for(auto &x : g[c]) if(!dead[x.first] && x.first!=prev) rec(x.first,c);
    map<int,int> cnt;
    function<void (int,int,int,int)> dfs3 = [&](int cu,int prv,int st,int _depth){
        if(_depth>k) return;
        cnt[_depth] = cnt[_depth]?min(cnt[_depth],st):st;
        for(auto &x : g[cu]) if(!dead[x.first] && x.first!=prv)
            dfs3(x.first,cu,st+1,_depth+x.second);
    };
    function<void (int,int,int,int)> dfs4 = [&](int cu,int prv,int st,int _depth){
        if(_depth>k) return;
        if(cnt[k-_depth]) ans = min(ans,st+cnt[k-_depth]);
        for(auto &x : g[cu]) if(!dead[x.first] && x.first!=prv)
            dfs4(x.first,cu,st+1,_depth+x.second);
    };
    dfs3(c,prev,0,0);
    if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
    for(auto &x : g[c]) if(!dead[x.first] && x.first!=prev){
        dfs4(x.first,c,1,x.second);
        dfs3(x.first,c,1,x.second);
    }
    dead[c] = 0;
}
int best_path(int _n,int _k,int h[][2],int l[]){
    ans = 1e9;
    n = _n; k = _k;
    for(int i=0;i<n-1;i++){
        int a = h[i][0];
        int b = h[i][1];
        int c = l[i];
        g[a].pb(mp(b,c));
        g[b].pb(mp(a,c));
    }
    rec(0);
    if(ans>=1e9) ans = -1;
    return ans;
}

Compilation message

race.cpp: In function 'void rec(int)':
race.cpp:30:53: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator!='
     for(auto &x : g[c]) if(!dead[x.first] && x.first!=prev) rec(x.first,c);
                                              ~~~~~~~^~~~~~
race.cpp:30:74: error: too many arguments to function 'void rec(int)'
     for(auto &x : g[c]) if(!dead[x.first] && x.first!=prev) rec(x.first,c);
                                                                          ^
race.cpp:27:6: note: declared here
 void rec(int cur){
      ^~~
race.cpp:44:20: error: no match for call to '(std::function<void(int, int, int, int)>) (int&, <unresolved overloaded function type>, int, int)'
     dfs3(c,prev,0,0);
                    ^
In file included from /usr/include/c++/7/functional:58:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from race.cpp:1:
/usr/include/c++/7/bits/std_function.h:701:5: note: candidate: _Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {int, int, int, int}]
     function<_Res(_ArgTypes...)>::
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/std_function.h:701:5: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to 'int'
race.cpp:45:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
     ^~
race.cpp:45:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(cnt[k]) ans = min(ans,cnt[k]); cnt.clear();
                                       ^~~
race.cpp:46:53: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator!='
     for(auto &x : g[c]) if(!dead[x.first] && x.first!=prev){
                                              ~~~~~~~^~~~~~