CSES - Aalto Competitive Programming 2024 - wk12 - Mon - Results
Submission details
Task:Chain Reaction
Sender:aalto2024m_004
Submission time:2024-11-25 17:40:59 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:26:31: error: 'LLONG_MAX' was not declared in this scope
   26 |     vector<ll> max_charge(n, -LLONG_MAX);
      |                               ^~~~~~~~~
input/code.cpp:5:1: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    4 | #include <algorithm>
  +++ |+#include <climits>
    5 | using namespace std;

Code

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long int;

int main() {
    int n, s;
    cin >> n >> s;
    s--; 
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    vector<vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--; 
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<ll> max_charge(n, -LLONG_MAX); 
    max_charge[s] = 1;

    queue<int> q;
    q.push(s);
    vector<bool> visited(n, false);
    visited[s] = true;

    ll global_max = 1;

    while (!q.empty()) {
        int u = q.front();
        q.pop();

        for (int v : adj[u]) {
            if (!visited[v]) {
                visited[v] = true;

                ll new_charge1 = max_charge[u] + a[v] - a[u];
                ll new_charge2 = max_charge[u] + b[v] - b[u];

                max_charge[v] = max({max_charge[v], new_charge1, new_charge2});
                global_max = max(global_max, max_charge[v]);

                q.push(v);
            }
        }
    }

    cout << global_max << endl;
}