Submission #896087

#TimeUsernameProblemLanguageResultExecution timeMemory
896087starchanRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include "race.h" #include<bits/stdc++.h> using namespace std; #define in pair<int, int> #define f first #define s second #define pb push_back #define pob pop_back #define INF (int)1e17 #define MX (int)3e5+5 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) int n, k; vector<in> adj[MX]; int sz[MX]; vector<bool> cut; void dfs1(int u, int p) { sz[u] = 1; for(in vw: adj[u]) { int v = vw.f; if(cut[v]) continue; if(v == p) continue; dfs1(v, u); sz[u]+=sz[v]; } return; } vector<int> comp[MX]; map<in, in> data; vector<int> centr[MX]; int centroid(int root, int u, int p) { for(in vw: adj[u]) { int v = vw.f; if(cut[v]) continue; if(v==p) continue; if(2*sz[v] > sz[root]) return centroid(root, v, u); } return u; } void dfs2(int root, int u, int p, int lvl, int d) { comp[root].pb(u); data[{root, u}] = {d, lvl}; for(in vw: adj[u]) { int v = vw.f; int w = vw.s; if(cut[v]) continue; if(v==p) continue; int cost = d+w; if(cost > k) cost = k+1; dfs2(root, v, u, lvl+1, cost); } return; } int centroid_decomposition(int u) { dfs1(u, -1); int root = centroid(u, u, -1); dfs2(root, root, -1, 0, 0); cut[root] = 1; for(in vw: adj[root]) { int v = vw.f; if(cut[v]) continue; centr[root].pb(centroid_decomposition(v)); } return root; } int dfs3(int u, int p) { int ans = n+1; map<int, int> freq; freq[0] = 0; for(int v: centr[u]) { ans = min(ans, dfs3(v, u)); for(int UVW: comp[v]) { in L_edge = data[{u, UVW}]; int L = L_edge.f; int dep = L_edge.s; if(L > k) continue; if(freq.find(k-L) == freq.end()) continue; ans = min(ans, dep+freq[k-L]); } for(int UVW: comp[v]) { in L_edge = data[{u, UVW}]; int L = L_edge.f; int dep = L_edge.s; if(freq.find(L) == freq.end()) freq[L] = dep; else freq[L] = min(freq[L], dep); } } return ans; } int best_path(int N, int K, int h[][2], int L[]) { n = N; k = K; for(int i = 1; i <= n; i++) adj[i].clear(); for(int i = 0; i < n-1; i++) { int u = h[i][0]; int v = h[i][1]; u++; v++; int l = L[i]; adj[u].pb({v, l}); adj[v].pb({u, l}); } cut.assign(n+1, 0); int root = centroid_decomposition(1); int ans = dfs3(root, -1); if(ans == (n+1)) ans = -1; return ans; } /* signed main() { int V, KK; cin >> V >> KK; int h[V-1][2]; int L[V-1]; for(int i = 0; i < V-1; i++) cin >> h[i][0] >> h[i][1] >> L[i]; int ok = best_path(V, KK, h, L); cout << ok << endl; return 0; } n k edge edge weight */

Compilation message (stderr)

race.cpp: In function 'void dfs2(int, int, int, int, int)':
race.cpp:52:2: error: reference to 'data' is ambiguous
   52 |  data[{root, u}] = {d, lvl};
      |  ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
race.cpp:33:13: note:                 'std::map<std::pair<int, int>, std::pair<int, int> > data'
   33 | map<in, in> data;
      |             ^~~~
race.cpp: In function 'int dfs3(int, int)':
race.cpp:93:16: error: reference to 'data' is ambiguous
   93 |    in L_edge = data[{u, UVW}];
      |                ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
race.cpp:33:13: note:                 'std::map<std::pair<int, int>, std::pair<int, int> > data'
   33 | map<in, in> data;
      |             ^~~~
race.cpp:104:16: error: reference to 'data' is ambiguous
  104 |    in L_edge = data[{u, UVW}];
      |                ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
race.cpp:33:13: note:                 'std::map<std::pair<int, int>, std::pair<int, int> > data'
   33 | map<in, in> data;
      |             ^~~~