Submission #98646

#TimeUsernameProblemLanguageResultExecution timeMemory
98646PeppaPigRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <race.h> #include <bits/stdc++.h> #define long long long #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 2e5 + 5; int n, k, ans = INT_MAX; int hv[N], in[N], out[N], pos[N], par[N], dep[N]; long d[N]; map<long, int> mp; vector<pii> g[N]; int gethv(int u, int v) { static int idx = 0; int sz = 1; pii ret(0, -1); par[u] = p, in[u] = ++idx, pos[idx] = u; for(pii v : g[u]) if(v.x != p) { d[v.x] = d[u] + v.y; dep[v.x] = dep[u] + 1; int z = gethv(v.x, u); sz += z, ret = max(ret, (z, v.x)); } out[u] = idx, hv[u] = ret.y; return sz; } void add(int u) { if(!mp.count(d[u])) mp[d[u]] = dep[u]; else mp[d[u]] = min(mp[d[u]], dep[u]); } void getans(int u, int lca) { long ret = k - d[u] + 2*d[lca]; if(mp.count(ret)) { int z = mp[ret] + dep[u] - 2*dep[lca]; ans = min(ans, z); } } void dfs(int u, int p, bool keep) { for(pii v : g[u]) if(v.x != p && v.x != hv[u]) dfs(v.x, u, 0); if(hv[u] != -1) dfs(hv[u], u, 1); getans(u, u), add(u); for(pii v : g[u]) if(v.x != p && v.x != hv[u]) { for(int i = in[v.x]; i <= out[v.x]; i++) getans(pos[i], u); for(int i = in[v.x]; i <= out[v.x]; i++) add(pos[i], u); } if(!keep) mp.clear(); } int best_path(int N, int K, int H[][2], int L[]) { n = N, k = K; for(int i = 0; i < N - 1; i++) { g[H[i][0]].emplace_back(H[i][1], L[i]); g[H[i][1]].emplace_back(H[i][0], L[i]); } gethv(0, 0); dfs(0, 0, 1); return ans; }

Compilation message (stderr)

race.cpp: In function 'int gethv(int, int)':
race.cpp:22:11: error: 'p' was not declared in this scope
  par[u] = p, in[u] = ++idx, pos[idx] = u;
           ^
race.cpp:6:11: warning: left operand of comma operator has no effect [-Wunused-value]
 #define x first
           ^
race.cpp:27:33: note: in expansion of macro 'x'
   sz += z, ret = max(ret, (z, v.x));
                                 ^
race.cpp:27:35: error: no matching function for call to 'max(std::pair<int, int>&, int&)'
   sz += z, ret = max(ret, (z, v.x));
                                   ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from race.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
race.cpp:27:35: note:   deduced conflicting types for parameter 'const _Tp' ('std::pair<int, int>' and 'int')
   sz += z, ret = max(ret, (z, v.x));
                                   ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from race.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
race.cpp:27:35: note:   deduced conflicting types for parameter 'const _Tp' ('std::pair<int, int>' and 'int')
   sz += z, ret = max(ret, (z, v.x));
                                   ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
race.cpp:27:35: note:   'std::pair<int, int>' is not derived from 'std::initializer_list<_Tp>'
   sz += z, ret = max(ret, (z, v.x));
                                   ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
race.cpp:27:35: note:   'std::pair<int, int>' is not derived from 'std::initializer_list<_Tp>'
   sz += z, ret = max(ret, (z, v.x));
                                   ^
race.cpp: In function 'void dfs(int, int, bool)':
race.cpp:52:57: error: too many arguments to function 'void add(int)'
   for(int i = in[v.x]; i <= out[v.x]; i++) add(pos[i], u);
                                                         ^
race.cpp:33:6: note: declared here
 void add(int u) {
      ^~~