Submission #1283383

#TimeUsernameProblemLanguageResultExecution timeMemory
1283383am_aadvikPower Plant (JOI20_power)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

vector<int> g[2000005], p;
int dp[2000005][2];
int dfs(int node, int b, int par) {
    if (dp[node][b] != -1) return dp[node][b];
    int mc1 = 0, mc0 = 0, sc1 = 0;
    for (auto x : g[node])
        if (x != par) {
            mc1 = max(mc1, dfs(x, 1, node));
            sc1 += dfs(x, 1, node);
            mc0 = max(mc0, dfs(x, 0, node));
        }
    int c1 = ((b == 0) ? mc1 : 0) + p[node];
    int c2 = ((b == 0) ? mc0 : 0);
    int c3 = ((b == 0) ? max(sc1, mc0) : sc1) - p[node];
    return dp[node][b] = max({ c1, c2, c3 });
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n; p.assign(n + 1, 0);
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    string s; cin >> s;
    for (int i = 1; i <= n; ++i)
        p[i] = (s[i - 1] - '0');
    memset(dp, -1, sizeof(dp));
    cout << dfs(1, 0, 0) << '\n';
}

Compilation message (stderr)

power.cpp: In function 'int dfs(int, int, int)':
power.cpp:20:29: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   20 |     return dp[node][b] = max({ c1, c2, c3 });
      |                          ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/string:51,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from power.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
power.cpp:20:29: note:   candidate expects 2 arguments, 1 provided
   20 |     return dp[node][b] = max({ c1, c2, c3 });
      |                          ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
power.cpp:20:29: note:   candidate expects 3 arguments, 1 provided
   20 |     return dp[node][b] = max({ c1, c2, c3 });
      |                          ~~~^~~~~~~~~~~~~~~~