# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
412701 | 2021-05-27T11:13:30 Z | LastRonin | Beads and wires (APIO14_beads) | C++14 | Compilation error |
0 ms | 0 KB |
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define ll long long #define pb push_back #define mp make_pair #define f first #define s second #define pill pair<ll, ll> using namespace std; const ll N = 1e4 + 10; const ll big = 1e18; ll n; vector<pill> g[N]; int dp[N][2], dp2[2][3], dp3[2][2]; int dfs(ll v, ll p, ll z) { dp[v][0] = dp[v][1] = 0; for(auto u : g[v]) { if(u.f != p) dfs(u.f, v, u.s); } dp2[0][0] = 0, dp2[0][1] = -big, dp2[0][2] = -big; for(auto u : g[v]) { if(u.f == p)continue; dp2[1][0] = dp2[0][0] + max(dp[u.f][0], dp[u.f][1]); dp2[1][1] = max(dp2[0][1] + max(dp[u.f][0], dp[u.f][1]), dp2[0][0] + dp[u.f][0] + u.s); dp2[1][2] = max(dp2[0][2] + max(dp[u.f][0], dp[u.f][1]), dp2[0][1] + dp[u.f][0] + u.s); dp2[0][0] = dp2[1][0]; dp2[0][1] = dp2[1][1]; dp2[0][2] = dp2[1][2]; } dp[v][0] = dp2[0][0]; dp[v][1] = dp2[0][1] + z; return dp2[0][2]; } int main() { speed; cin >> n; for(int i = 1, a, b, c; i < n; i++) cin >> a >> b >> c, g[a].pb(mp(b, c)), g[b].pb(mp(a, c)); ll ans = 0; for(int i = 1; i <= n; i++) ans = max(ans, dfs(i, 0, 0)); cout << ans; } /* 10 5 6 9 2 3 5 1 10 8 4 5 9 2 7 8 5 7 10 6 9 4 2 8 9 1 7 5 10 4 10 2 1 2 21 1 3 13 6 7 1 7 9 5 2 4 3 2 5 8 1 6 55 6 8 34 */
Compilation message
beads.cpp: In function 'int dfs(long long int, long long int, long long int)': beads.cpp:23:29: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow] 23 | dp2[0][0] = 0, dp2[0][1] = -big, dp2[0][2] = -big; | ^~~~ beads.cpp:23:47: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow] 23 | dp2[0][0] = 0, dp2[0][1] = -big, dp2[0][2] = -big; | ^~~~ beads.cpp:27:88: error: no matching function for call to 'max(int, long long int)' 27 | dp2[1][1] = max(dp2[0][1] + max(dp[u.f][0], dp[u.f][1]), dp2[0][0] + dp[u.f][0] + u.s); | ^ 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:1: /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:27:88: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 27 | dp2[1][1] = max(dp2[0][1] + max(dp[u.f][0], dp[u.f][1]), dp2[0][0] + dp[u.f][0] + u.s); | ^ 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:1: /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:27:88: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 27 | dp2[1][1] = max(dp2[0][1] + max(dp[u.f][0], dp[u.f][1]), dp2[0][0] + dp[u.f][0] + u.s); | ^ 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:1: /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:27:88: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 27 | dp2[1][1] = max(dp2[0][1] + max(dp[u.f][0], dp[u.f][1]), dp2[0][0] + dp[u.f][0] + u.s); | ^ 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:1: /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:27:88: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 27 | dp2[1][1] = max(dp2[0][1] + max(dp[u.f][0], dp[u.f][1]), dp2[0][0] + dp[u.f][0] + u.s); | ^ beads.cpp:28:88: error: no matching function for call to 'max(int, long long int)' 28 | dp2[1][2] = max(dp2[0][2] + max(dp[u.f][0], dp[u.f][1]), dp2[0][1] + dp[u.f][0] + u.s); | ^ 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:1: /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:28:88: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 28 | dp2[1][2] = max(dp2[0][2] + max(dp[u.f][0], dp[u.f][1]), dp2[0][1] + dp[u.f][0] + u.s); | ^ 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:1: /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:28:88: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 28 | dp2[1][2] = max(dp2[0][2] + max(dp[u.f][0], dp[u.f][1]), dp2[0][1] + dp[u.f][0] + u.s); | ^ 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:1: /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:28:88: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 28 | dp2[1][2] = max(dp2[0][2] + max(dp[u.f][0], dp[u.f][1]), dp2[0][1] + dp[u.f][0] + u.s); | ^ 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:1: /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:28:88: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 28 | dp2[1][2] = max(dp2[0][2] + max(dp[u.f][0], dp[u.f][1]), dp2[0][1] + dp[u.f][0] + u.s); | ^ beads.cpp: In function 'int main()': beads.cpp:45:30: error: no matching function for call to 'max(long long int&, int)' 45 | ans = max(ans, dfs(i, 0, 0)); | ^ 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:1: /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:45:30: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 45 | ans = max(ans, dfs(i, 0, 0)); | ^ 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:1: /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:45:30: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 45 | ans = max(ans, dfs(i, 0, 0)); | ^ 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:1: /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:45:30: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 45 | ans = max(ans, dfs(i, 0, 0)); | ^ 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:1: /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:45:30: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 45 | ans = max(ans, dfs(i, 0, 0)); | ^