Submission #1155238

#TimeUsernameProblemLanguageResultExecution timeMemory
1155238NeilPToll (APIO13_toll)C++20
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Edge{ int a; int b; int cost; }; int n, m, k; vector<vector<pair<int, int>>> tree; bool comp(Edge a, Edge b){ return a.cost < b.cost; } vector<int> parent; vector<int> size; vector<int> tots; int find(int x){ if(parent[x] == x) return x; else { return (parent[x] = find(parent[x])); } } void merge(int x, int y){ int xh = find(x); int yh = find(y); if(xh == yh) return; if(size[xh] > size[yh]) swap(xh, yh); parent[xh] = yh; size[yh] += size[xh]; } pair<long long, long long> dfs(int x, int p) // (size, money) { pair<long long, long long> tot = {tots[x], 0}; for(pair<int, int> q: tree[x]){ if(q.first == p){ continue; } pair<long long, long long> res = dfs(q.first, x); tot.first += res.first; tot.second += 1LL * q.second * res.first; } return tot; } int main() { cin >> n >> m >> k; for(int i = 0; i < n; i++){ parent.push_back(i); size.push_back(1); } int start[20], end[20], toll[20]; vector<Edge> edges; for(int i = 0; i < m; i++){ int u, v, c; cin >> u >> v >> c; u--; v--; Edge e = {u, v, c}; edges.push_back(e); } sort(edges.begin(), edges.end(), comp); for(int i = 0; i < k; i++){ cin >> start[i] >> end[i]; start[i]--; end[i]--; } tots = vector<int>(n); for(int i = 0; i < n; i++) cin >> tots[i]; tree = vector<vector<pair<int, int>>>(n); for(Edge e : edges){ int x_comp = find(e.a); int y_comp = find(e.b); if(x_comp == y_comp) continue; for(int i = 0; i < k; i++){ int u_c = find(start[i]); int v_c = find(end[i]); if((u_c == x_comp && v_c == y_comp) || (v_c == x_comp && u_c == y_comp)){ toll[i] = e.cost; tree[start[i]].push_back({end[i], toll[i]}); tree[end[i]].push_back({start[i], toll[i]}); merge(x_comp, y_comp); break; } } x_comp = find(e.a); y_comp = find(e.b); if(x_comp == y_comp) continue; merge(x_comp, y_comp); tree[e.a].push_back({e.b, 0}); tree[e.b].push_back({e.a, 0}); } pair<int, int> res = dfs(0, -1); cout << res.second << endl; return 0; }

Compilation message (stderr)

toll.cpp: In function 'void merge(int, int)':
toll.cpp:37:8: error: reference to 'size' is ambiguous
   37 |     if(size[xh] > size[yh])
      |        ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from toll.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
toll.cpp:20:13: note:                 'std::vector<int> size'
   20 | vector<int> size;
      |             ^~~~
toll.cpp:37:19: error: reference to 'size' is ambiguous
   37 |     if(size[xh] > size[yh])
      |                   ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from toll.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
toll.cpp:20:13: note:                 'std::vector<int> size'
   20 | vector<int> size;
      |             ^~~~
toll.cpp:40:5: error: reference to 'size' is ambiguous
   40 |     size[yh] += size[xh];
      |     ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from toll.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
toll.cpp:20:13: note:                 'std::vector<int> size'
   20 | vector<int> size;
      |             ^~~~
toll.cpp:40:17: error: reference to 'size' is ambiguous
   40 |     size[yh] += size[xh];
      |                 ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from toll.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
toll.cpp:20:13: note:                 'std::vector<int> size'
   20 | vector<int> size;
      |             ^~~~
toll.cpp: In function 'int main()':
toll.cpp:63:9: error: reference to 'size' is ambiguous
   63 |         size.push_back(1);
      |         ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from toll.cpp:1:
/usr/include/c++/11/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
toll.cpp:20:13: note:                 'std::vector<int> size'
   20 | vector<int> size;
      |             ^~~~