제출 #908138

#제출 시각아이디문제언어결과실행 시간메모리
908138duckindog구슬과 끈 (APIO14_beads)C++14
컴파일 에러
0 ms0 KiB
// 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; }

컴파일 시 표준 에러 (stderr) 메시지

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~