Submission #751995

# Submission time Handle Problem Language Result Execution time Memory
751995 2023-06-02T04:00:26 Z vjudge1 Beads and wires (APIO14_beads) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
long long dp[200100][2];
vector<pair<int, long long>> adj[200100];
void dfs(int n, int p) {
    dp[n][0] = 0;
    dp[n][1] = -1e18;
    long long m1=-1e18, m2=-1e18;
    for(auto [i, j]: adj[n]) {
        if(i!=p) {
            dfs(i, n);
            long long X = max(dp[i][1]+j, dp[i][0]);
            dp[n][0]+=X;
            long long x = dp[i][0] + j - X;
            if(m1 <= x)m2 = m1, m1 = x;
            else if(m2<x) m2 = x;
        }
    }
    dp[n][1]=dp[n][0]+m1;
    dp[n][0]+=max(0LL,m1+m2);
}
int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for(int i = 1; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    int m = -1e18;
    for(int i = 1; i <= n; i++) {
        dfs(i, 0);
        m = max(m, dp[i][0]);
    }
    cout << m << '\n';
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:33:13: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   33 |     int m = -1e18;
      |             ^~~~~
beads.cpp:36:28: error: no matching function for call to 'max(int&, long long int&)'
   36 |         m = max(m, dp[i][0]);
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 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:36:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   36 |         m = max(m, dp[i][0]);
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 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:36:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   36 |         m = max(m, dp[i][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:36:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |         m = max(m, dp[i][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:36:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |         m = max(m, dp[i][0]);
      |                            ^