답안 #571735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571735 2022-06-02T15:51:46 Z piOOE Chase (CEOI17_chase) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

const int N = 100001;

vector<int> g[N];
int n, k, parent[N], depth[N];
ll p[N], pp[N];

void dfs(int v) {
    for (int to: g[v]) {
        if (to != parent[v]) {
            parent[to] = v;
            depth[to] = depth[v] + 1;
            dfs(to);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    for (int r = 0; r < n; ++r) {
        parent[r] = r;
        depth[r] = 1;
        dfs(r);
        for (int v = 0; v < n; ++v) {
            if (depth[v] <= k) {
                memcpy(pp, p, sizeof(pp[0]) * n);
                ll cntnow = 0, cntnext = 0;
                int x = v;
                while (x != r) {
                    cntnow += pp[x];
                    for (int to: g[x]) {
                        pp[x] += pp[to];
                        pp[to] = 0;
                    }
                    x = parent[x];
                }
                {
                    cntnow += pp[x];
                    for (int to: g[x]) {
                        pp[x] += pp[to];
                        pp[to] = 0;
                    }
                }
                {
                    x = v;
                    while (x != r) {
                        cntnext += pp[x];
                        x = parent[x];
                    }
                    cntnext += pp[r];
                }
                ans = max(ans, cntnext - cntnow);
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:78:48: error: no matching function for call to 'max(int&, ll)'
   78 |                 ans = max(ans, cntnext - cntnow);
      |                                                ^
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 chase.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:
chase.cpp:78:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   78 |                 ans = max(ans, cntnext - cntnow);
      |                                                ^
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 chase.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:
chase.cpp:78:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   78 |                 ans = max(ans, cntnext - cntnow);
      |                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from chase.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:
chase.cpp:78:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   78 |                 ans = max(ans, cntnext - cntnow);
      |                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from chase.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:
chase.cpp:78:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   78 |                 ans = max(ans, cntnext - cntnow);
      |                                                ^