Submission #311691

#TimeUsernameProblemLanguageResultExecution timeMemory
311691thecodingwizardPutovanje (COCI20_putovanje)C++11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ii pair<int, int> #define f first #define s second #define mp make_pair #define pb push_back int n; vector<pair<int, ii>> adj[200000]; int pa[200000][20]; int depth[200000]; int in[200000], out[200000], ctr = 0; void dfs(int u, int p, int d) { in[u] = ctr++; pa[u][0] = p; depth[u] = d; for (auto v : adj[u]) { if (v.f != p) dfs(v.f, u, d+1); } out[u] = ctr-1; } int lca(int a, int b) { if (depth[a] < depth[b]) swap(a, b); for (int i = 19; i >= 0; i--) { if (depth[pa[a][i]] >= depth[b]) a = pa[a][i]; } if (a == b) return a; for (int i = 19; i >= 0; i--) { if (pa[a][i] != pa[b][i]) { a = pa[a][i], b = pa[b][i]; } } return pa[a][0]; } int ft[200001]; void upd(int k, int v) { k++; while (k <= 200000) { ft[k] += v; k += k&-k; } } int qry(int k) { k++; int ans = 0; while(k) { ans += ft[k]; k -= k&-k; } return ans; } ll ans = 0; void dfs2(int u, int p) { for (auto v : adj[u]) { if (v.f == p) continue; assert(depth[v.f] = depth[u]+1); ll numTraversals = qry(out[v.f]) - qry(in[v.f]-1); //cout << u << "->" << v.f << ": " << min(numTraversals*v.s.f, v.s.s) << endl; ans += min(numTraversals*v.s.f, v.s.s); dfs2(v.f, u); } } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 0; i < n-1; i++) { int a, b, c, d; cin >> a >> b >> c >> d; --a; --b; adj[a].push_back(mp(b, mp(c, d))); adj[b].push_back(mp(a, mp(c, d))); } dfs(0, 0, 0); for (int j = 0; j < 20; j++) { for (int i = 0; i < n; i++) { pa[i][j] = pa[pa[i][j-1]][j-1]; } } for (int i = 0; i < n-1; i++) { int x = lca(i, i+1); assert(depth[i] >= depth[x]); assert(depth[i+1] >= depth[x]); upd(in[i], 1); upd(in[i+1], 1); upd(in[x], -2); } dfs2(0, 0); cout << ans << endl; return 0; }

Compilation message (stderr)

putovanje.cpp: In function 'void dfs2(int, int)':
putovanje.cpp:67:46: error: no matching function for call to 'min(ll, int&)'
   67 |         ans += min(numTraversals*v.s.f, v.s.s);
      |                                              ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from putovanje.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
putovanje.cpp:67:46: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   67 |         ans += min(numTraversals*v.s.f, v.s.s);
      |                                              ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from putovanje.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
putovanje.cpp:67:46: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   67 |         ans += min(numTraversals*v.s.f, v.s.s);
      |                                              ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from putovanje.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
putovanje.cpp:67:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   67 |         ans += min(numTraversals*v.s.f, v.s.s);
      |                                              ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from putovanje.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
putovanje.cpp:67:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   67 |         ans += min(numTraversals*v.s.f, v.s.s);
      |                                              ^