Submission #908138

# Submission time Handle Problem Language Result Execution time Memory
908138 2024-01-16T08:26:48 Z duckindog Beads and wires (APIO14_beads) C++14
Compilation error
0 ms 0 KB
// from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
int n;
vector<pair<int, int>> ad[N];
int f[2][N];

int dfs(int u, int pre = 0) {
  int ret = 0;
  int all = -1e8, none = -1e8;
  for (auto duck : ad[u]) {
    int v, w; tie(v, w) = duck;
    if (v == pre) continue;
    if (all == -1e15) all = 0;
    dfs(v, u);
    ret = max(ret, f[0][v]);

    int best = max(f[1][v] + w, f[0][v]);
    all += best;
    none = max(none, f[0][v] + w - best);

  }
  f[0][u] = max(0ll, all);
  f[1][u] = all + none;
  return max(ret, f[0][u]);
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v, w; cin >> u >> v >> w;
    ad[u].push_back({v, w});
    ad[v].push_back({u, w});
  }

  int answer = 0;
  for (int i = 1; i <= n; ++i) {
    answer = max(answer, dfs(i));
  }
  cout << answer;

}

Compilation message

beads.cpp: In function 'int dfs(int, int)':
beads.cpp:26:25: error: no matching function for call to 'max(long long int, int&)'
   26 |   f[0][u] = max(0ll, all);
      |                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 beads.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
beads.cpp:26:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   26 |   f[0][u] = max(0ll, all);
      |                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 beads.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
beads.cpp:26:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   26 |   f[0][u] = max(0ll, all);
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from beads.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
beads.cpp:26:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   26 |   f[0][u] = max(0ll, all);
      |                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from beads.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
beads.cpp:26:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   26 |   f[0][u] = max(0ll, all);
      |                         ^
beads.cpp: In function 'int32_t main()':
beads.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
beads.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~