output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> class raw_input { public: template <typename T> raw_input& operator>>(T& arg) { if constexpr (std::is_integral<T>::value) { if constexpr (sizeof(T) == sizeof(int)) { scanf("%d", &arg); } else { scanf("%lld", &arg); } } if constexpr (std::is_flo...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; template <class T> void Read(T &x) { char c; bool f(0); while (c = getchar(), c != EOF) if (c == '-') f = 1; else if (c >= '0' && c <= '9') { x = c - '0'; while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0'; ungetc(c, stdin...
### Prompt Please provide a CPP coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; long long dp[200010][3]; long long cst[200010]; long long sz[200010]; long long visited[200010]; vector<vector<int>> vt; void dfs(long long here) { visited[here] = 1; sz[here] = cst[here]; vector<long long> gap; for (int i = 0; i < vt[here].size(); i++) { int ne...
### Prompt Generate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; template <class T> T mulmod(T a, T b) { if (b == 0) return 0; if (b == 1) return a; T x = mulmod(a, b >> 1); x = (x + x) % 1000000007; if (b & 1) x = (x + a) % 1000000007; return x; } template <class T> T larger(T a, T b) { return (a > b ? a : b); } template <...
### Prompt Please create a solution in Cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; vector<signed long long> pls; vector<list<int> > adj; vector<bool> visited; vector<signed long long> max_pls, max_pls2; vector<signed long long> tot_pls; vector<int> parent; void dfs_pls(int i) { visited[i] = true; for (auto j : adj[i]) { if (visited[j]) continue; ...
### Prompt Develop a solution in cpp to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; vector<int> adj[210000]; vector<long long> a(210000), sum(210000), mx(210000); int n; long long ans = -inf; void dfs(int u, int par) { vector<long long> tmp; sum[u] = a[u]; mx[u] = -inf; for (auto v : adj[u]) if (v != par) { dfs...
### Prompt Your challenge is to write a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; } const long long int inf = 1e15; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n...
### Prompt Create a solution in cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> best[200010]; vector<int> arr[200010]; long long subtree[200010]; int val[200010]; int n; long long maxans = -1e18; void dfs(int s, int parent) { subtree[s] = val[s]; long long maxx = -1e18, secmaxx = -1e18; for (int i = 0; i < arr[s].size()...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; bool desc_sort(const long long& lhs, const long long& rhs) { return lhs > rhs; } bool desc_pii_sort(const pair<int, int>& lhs, const pair<int, int>& rhs) { return lhs > rhs; } bool second_sort(const pair<int, int>& lhs, const pair<int, int>& rhs) { pair<int, int> a, b; ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int max_n = 200005; const long long inf = 1e18 + 8; int d[max_n]; int n; long long sum[max_n]; long long maxsum[max_n]; vector<int> v[max_n]; bool isbambuk = true; long long ans = -inf; void dfs(int cur, int pr) { if (v[cur].size() == 1 && v[cur][0] == pr) { sum...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-9; const int MAXN = 1e5 + 10; int mod = 1e9 + 7; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int a[3000005]; vector<int> adj[400000]; long long best[400000]; long long sum[400000]; long ...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const int MX = 123; const int MOD = int(360); const long long oo = LLONG_MAX; pair<long long, long long> go(vector<vector<int> >& graph, vector<long long>& a, int p, int u, bool& can, long long& ans) { long long sum = a[u]; long long best0 ...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 22; const long long INF = 2e18 + 2; int n; long long res = -INF * 2; long long a[MAXN], mx[MAXN], sum[MAXN]; vector<int> G[MAXN]; void dfs(int v, int par) { sum[v] = a[v]; for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; if (u == p...
### Prompt Create a solution in cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; long long dp[200010], v[200010], sum[200010]; int head[200010], to[200010 * 2], pre[200010 * 2]; int n, e; long long ans; void addedge(int x, int y) { to[e] = y; pre[e] = head[x]; head[x] = e++; } void dfs(int x, int pa) { sum[x] = v[x]; ...
### Prompt Construct a cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200000; const long long LINF = 1LL << 62; int as[MAX_N], ps[MAX_N], cns[MAX_N]; vector<int> nbrs[MAX_N]; long long ss[MAX_N], dp0[MAX_N], dp1[MAX_N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i =...
### Prompt Your challenge is to write a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1000000000000000000; long long mod = 1000000000; long double pi = 3.141592653589793238; void pls() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long mul_mod(long long a, long long b, long long m) { long long x = 0, y = a; w...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; static const int max_n = (2e+5) + 1; static const long long INF = 1e+17; static const long long INF_M = -INF; static const long long INF_M_2 = 2 * INF_M; int pleasant[max_n] = {}; long long pleasant_sub[max_n] = {}; vector<int> conns[max_n]; long long dp1[max_n]; long long ...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 20; int n, a[N], i, u, v; vector<int> adj[N]; long long dp[N], sum[N], ans = LLONG_MIN; void dfs(int node, int p) { sum[node] = a[node]; for (auto i : adj[node]) { if (i == p) continue; dfs(i, node); sum[node] += sum[i]; if (dp[node] ...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; int n; int w[200100]; int f[200100]; int sm[200100]; long long an[200100], w1[200100], w2[200100], mx[200100]; int a[200100], b[200100]; vector<int> E[200100]; queue<int> Q; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &w[i]); for (int i = 1;...
### Prompt Construct a cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T qmin(const T a, const T b) { return a < b ? a : b; } template <typename T> inline T qmax(const T a, const T b) { return a > b ? a : b; } template <typename T> inline void getmin(T &a, const T b) { if (a > b) a = b; } template <typename T...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; long long num[200000], dp[200000][2], ans = -1e18; vector<int> r[200000]; void dfs(int now, int par) { long long sum = 0, max1 = -1e18, max2 = -1e18; dp[now][0] = num[now]; for (int i = 0; i < r[now].size(); i++) if (r[now][i] != par) { dfs(r[now][i], now); ...
### Prompt Your challenge is to write a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const long long minn = -100000000000000000LL; long long a[200010]; vector<int> G[200010]; long long dp[200010][2]; long long sum[200020]; long long ans = 0; void dfs(int u, int fa) { sum[u] = a[u]; dp[u][0] = dp[u][1] = minn; for (int i = 0; i < G[u].size(); i++) { ...
### Prompt Please create a solution in cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> mx[200005]; long long sum[200005]; vector<long long> g[200005]; bool vis[200005]; long long ans = -1e16; long long getsum(int ver) { vis[ver] = true; for (int i = 0; i < g[ver].size(); i++) { int child = g[ver][i]; if (vis[child]) cont...
### Prompt Generate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 100000 + 10; const long long llinf = (long long)1 << 62; int a[maxn], n; vector<int> g[maxn]; long long sum_subTree[maxn], mx_subTree[maxn], ans = -llinf; void dfs1(int v, int p) { sum_subTree[v] = a[v]; mx_subTree[v] = -llinf; for (int i = 0; i <...
### Prompt Please provide a Cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; int n; int a[200001]; long long sum[200001]; long long mx[200001]; bool vis[200001]; vector<int> conn[200001]; long long computeSum(int i) { if (vis[i]) return 0; vis[i] = true; long long s = a[i]; for (int j = 0; j < conn[i].size(); j++) { if (conn[i][j] == -1)...
### Prompt Please provide a cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long LINF = 1e17; const double PI = 3.141592653589793238; const int mod = 1000000007; const double eps = 0.000001; template <typename T, typename TT> ostream &operator<<(ostream &s, pair<T, TT> t) { return s << "(" << t.first << "," ...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const long long NINF = 0xdddddddddddddddd; const int maxn = 2e5 + 11; int N, M, T, P, Q; int a[maxn]; list<int> G[maxn]; long long sum[maxn]; int sz[maxn], l[maxn], r[maxn], ver[maxn << 1]; i...
### Prompt Please create a solution in CPP to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; int n; int val[200005]; vector<int> adj[200005]; long long sum[200005]; long long max_sum[200005]; bool chain(int u, int p) { int cnt = 0; for (int v : adj[u]) { if (v == p) continue; if (++cnt > 1) return false; if (!chain(v, u)) return false; } return ...
### Prompt Please provide a Cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int maxn = 200100, maxm = 500100; const long long infinit = 0x007f7f7f7f7f7f7fll; class TreeDP { public: struct edge { int u, v; edge *next; }; int n, root, ecnt; edge *edges[maxn], epool[maxm]; long long val[maxn], sum[maxn]; long long dp[maxn][3...
### Prompt Your challenge is to write a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int N = 200005; vector<int> g[N]; long long int sm[N], mx[N]; int A[N]; long long int ans; void dfs(int c, int p) { sm[c] = A[c]; for (int i = 0; i < g[c].size(); i++) { int u = g[c][i]; if (u != p) { dfs(u, c); } } for (int i = 0; i < g[c].s...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> static long long solve(const std::vector<std::vector<long> > &g, const std::vector<long> &weight, long s, long p, std::vector<long long> &total_w, std::vector<long long> &max_sum) { std::vector<long long> m; m.reserve(g[s]...
### Prompt Generate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T min(T a, T b, T c, T d) { return min(a, min(b, min(c, d))); } template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T max(T a, T b, T c, T d) ...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; vector<int> g[200001]; long long ans[200001]; long long a[200001]; long long sum[200001]; int u[200001]; int pr[200001]; void dfs(int v) { u[v] = 1; sum[v] = a[v]; for (int i = 0; i < g[v].size(); i++) { if (!u[g[v][i]]) { pr[g[v][i]] = v; dfs(g[v][i])...
### Prompt Please formulate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a < b) return b; return a; } long long min(long long a, long long b) { if (a < b) return a; return b; } vector<vector<long long>> v(200005); long long pleasure[200005], subtree[200005]; long long ans = -((1LL << 60) - 1)...
### Prompt Please formulate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const long long maxn = 200010; const long long inf = 1e18; long long n, u, v, cnt, ans = -inf, a[maxn], num[maxn], f[maxn], indeg[maxn], head[maxn << 1]; struct node { long long to, nxt; } e[maxn << 1]; void add(long long u, long long v) { e[++cn...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; vector<int> A; vector<vector<int>> adjList, C; vector<long long> r_solve(int node) { long long curr_val, max_val, max_sum; curr_val = max_val = max_sum = 0; curr_val = A[node]; max_val = max_sum = (long long)-10e16; vector<long long> S; for (int child : C[node])...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const long long N = 200003; long long inf = -10e17 + 3; vector<long long> v[N]; long long sum[N], msum[N], val[N], ans = inf; void dfs(long long ver, long long par) { msum[ver] = inf; for (auto it : v[ver]) { if (it == par) continue; dfs(it, ver); if (msum[i...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int N = 2 * 1e5 + 10; int tin[2 * N], tout[2 * N]; long long t[8 * N], a[N]; int timer, ver[2 * N]; vector<int> g[N]; void dfs(int v, int p = -1) { tin[v] = ++timer; ver[timer] = v; for (int i = 0; i < g[v].size(); i++) { int to =...
### Prompt Develop a solution in cpp to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; vector<int> v[200005]; int vis[200005]; long long arr[200005]; long long su[200005]; long long dp[200005]; int n; int cou; long long fin; long long bes1, bes2; const long long INF = 1E16; void dfs(int ind) { vis[ind] = 1; dp[ind] = -INF; su[ind] = arr[ind]; vector<l...
### Prompt In CPP, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238; long long powmod(long long a, long long b) { long long res = 1; a %= 1000000007; for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } vector<int> vec[200005]; long long ...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const int N = 200001; vector<int> g[N]; long long a[N], d[N], s[N]; bool joke = false; long long sum(int v, int p) { if (s[v] != -11111LL) { return s[v]; } s[v] = 0LL; for (int i = 0; i < (int)g[v].size(); ++i) { int u = g[v][i]; if (u != p) { s[v]...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e15; const long long int mod = 1000000007; const int infInt = 1e9; const double PI = acos(-1.00); const double eps = 1e-6; long long int weight[200010]; long long int dp[200010]; vector<vector<int> > adj; vector<vector<int> > level; int vis[200010...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "yes" : "no"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { x += y; if (x >= mod) x -= mod; ...
### Prompt Create a solution in Cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const long long int INF = 98769876987698889LL; const int MOD = 1e9 + 7; const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx4[] = {1, -1, 0, 0}; const int dy4[] = {0, 0, 1, -1}; const int N = 2e5 + 5; long long int dp1[N...
### Prompt Please formulate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e17; const int N = 3e5 + 7; int n, m; int c[N]; vector<int> g[N]; long long w[N], sum = -inf, f[N]; bool imp = true; void dfs(int v, int p) { w[v] += c[v]; int cnt = 0; for (int u : g[v]) { if (u != p) { dfs(u, v); f[v] = max(f[u...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; vector<int> tree[200010]; long long a[200010]; long long sumx[200010]; long long mxx[200010]; long long gl; void dfs(int v, int par) { long long ans = a[v]; for (int i = 0; i < tree[v].size(); i++) { int u = tree[v][i]; if (u != par) { dfs(u, v); ans...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-8; int n; int a[200005]; int u[200005]; int v[200005]; vector<int> edges[200005]; long long int dp[200005][2]; bool visited[200005]; long long int ans; bool good; pair<long long int, long long int> dfs(int node, int par) { ...
### Prompt Construct a CPP code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18 + 1; const int N = 300300; int n; long long ans = -INF; long long a[N]; long long sum[N]; vector<int> g[N]; bool used[N]; void dfs(int v) { used[v] = 1; sum[v] = a[v]; a[v] = -INF; long long m1 = -INF, m2 = -INF; for (int u : ...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; int n; const int Max = 200050; struct zk { int v, next; } ed[Max << 1]; int w[Max]; long long ans = -1e18; bool flag; vector<int> G[Max]; long long dp[Max][2]; void dfs(int u, int fa) { dp[u][0] = w[u]; int sz = G[u].size(); long long max1 = -1e18, max2 = -1e18; f...
### Prompt Create a solution in Cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> g[N]; long long int a[N], sub[N]; long long int global_ans = -1e18; bool possible = false; void subSum(int par, int node) { sub[node] = a[node]; for (int adj : g[node]) { if (adj == par) continue; subSum(node, adj); sub[nod...
### Prompt Construct a CPP code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int N = (int)1e6 + 7; const int MOD = (int)1e9 + 7; const int INF = (int)2e9; const long long BIG = 1e18; vector<vector<int> > g(N); long long a[N], sum[N], max_sum[N], ans = -BIG; void dfs(int v = 1, int p = -1) { ...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC optimize("O0") #pragma GCC optimize("O1") using namespace std; const int N = 2 * 1e5 + 10; int n; int a[N]; long long res = LONG_LONG_MIN; long long sum[N], maxi[N]; vector<int> adj[N]; bool mark[N]; void dfs(int x) ...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> long long mod = 10000000000000007ll; using namespace std; int n; long long ans; long long c[2 * 100001]; long long sub[2 * 100001]; vector<int> G[2 * 100001]; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod;...
### Prompt Your challenge is to write a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; long long maxx(long long a, long long b) { return (a < b) ? b : a; } vector<vector<long long> > graph(200010); vector<long long> pls(200010); vector<long long> pls_tree(200010); vector<bool> visited(200010, false); vector<pair<bool, long long> > max1(200010, make_pair(false...
### Prompt Your challenge is to write a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200000, MAX_VAL = 1000000000; const long long INF = (long long)(MAX_N) * (long long)(MAX_VAL) + 1ll; struct Vertex { int a; long long s, maxim, ans; list<int> edge; }; int n, a[MAX_N + 1]; Vertex vertexs[MAX_N + 1]; void DFS(int v, int p = 0) { ver...
### Prompt Develop a solution in cpp to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const long long INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == '-') && (flag = true); for (res = ch - 48; isdigit(ch = getchar()); res = (res ...
### Prompt Construct a cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const long long p = 1e5; vector<long long> a, sum, mxn; vector<long long> adjList[2 * p]; vector<bool> visited; long long mx = INT_MIN, n; void dfs1(long long s) { visited[s] = true; for (int i = 0; i < adjList[s].size(); i++) { if (!visited[adjList[s][i]]) { ...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; int n, x, y; long long val[200005], mx[200005], cnt[200005], t[200005], ans = -1e18; vector<int> v[200005]; bool cmp(long long x, long long y) { return x > y; } void dfs(int node, int par) { cnt[node] += val[node]; for (int i = 0; i < v[node].size(); i++) { if (v[no...
### Prompt Please provide a Cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; long long a[1000000 + 100], sol, n, k, x, y, d[1000000 + 100], pr[200010][20], f[1000000 + 100], d1, poen[1000000 + 100], otac[1000000 + 100]; long long drugi, idx2, max1, k1, k2, sin1[1000000 + 100], sin2[1000000 + 100]; long long D = 20; long long mapa[1000000 + 100];...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> const long long inf = -100000000000000000LL; const int maxn = 2 * 1e5 + 10; using namespace std; long long val[maxn], son[maxn]; int head[maxn], n, k; long long ans, dp[maxn]; long long max(long long a, long long b) { return a > b ? a : b; } struct edge { int v, next; } e[maxn << 1]; void add...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; const long long INF = 1e18; long long a[N]; long long n; vector<long long> g[N]; long long subtree[N], dp[N]; long long ans; void dfs(long long node, long long par = -1) { subtree[node] = a[node]; long long mx1 = -INF, mx2 = -INF; for (lon...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> int getint(int x = 0) { scanf("%d", &x); return x; } double getdb(double x = 0) { scanf("%lf", &x); return x; } long long getll(long long x = 0) { scanf("%I64d", &x); return x; } using namespace std; long long INF = 1; struct edge { int in; edge* nxt; }; edge pool[405000]; edge*...
### Prompt Your challenge is to write a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:247474112") #pragma GCC optimize("Ofast") using namespace std; const long long maxn = 2e5 + 10; long long mx[maxn], val[maxn], sum[maxn]; vector<long long> g[maxn]; long long pass[maxn]; bool ok = 0; long long ans = LLONG_MIN; void dfs(long long aa = 1, long long...
### Prompt Your challenge is to write a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; int a[200100]; long long val[200100]; long long mx[200100]; vector<int> adj[200100]; bool ok = 0; long long ans = -1000000000000000ll; void dfs(int u, int fa = 0) { val[u] += a[u]; long long Mx1 = -1000000000000000ll, Mx2 = -1000000000000000ll, Mx; for (auto v : adj[u...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; long long sum[200005]; long long bch[200005]; int a[200005]; vector<int> ady[200005]; long long tans = -0x3f3f3f3f3f3f3f3fLL; void dfs(int v, int p) { sum[v] = a[v]; bch[v] = -0x3f3f3f3f3f3f3f3fLL; for (int dv : ady[v]) { if (dv != p) { dfs(dv, v); sum...
### Prompt Please create a solution in CPP to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int N = 200100; long long a[N], w[N]; int u[N], tin[N], tout[N], tt = 0; vector<int> g[N]; struct nd { int l, r; long long w; nd() {} }; void dfs(int v) { if (u[v]) { return; } w[v] = a[v]; u[v] = 1; tin[v] = ++tt; for (auto i : g[v]) { if (!...
### Prompt Please provide a cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; template <class S, class T> ostream& operator<<(ostream& os, const pair<S, T>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> void debug(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << ...
### Prompt Please create a solution in CPP to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; long long n, val[200200]; long long siz[200020], maxi[200020]; vector<long long> graph[200300]; long long ans[200202]; void dfs(int start, int par) { multiset<long long> s; int sizz = graph[start].size(); int i; siz[start] = val[start]; long long damru = -99999999...
### Prompt Please provide a CPP coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> const long long LL_INF = (long long)2e18 + 5; using namespace std; void __print(int32_t x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long ...
### Prompt Please formulate a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long power(long long first, long long n) { if (n == 0) return 1; if (n % 2) return (first % mod * power((first % mod * first % mod) % mod, n / 2) % mod) % mod; return power((first % mod * first % mod) % mod, n /...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 1e-7; const long long inf = 1e17; long long n; vector<long long> in; vector<vector<long long> > G; vector<long long> sum, used; long long dfs(int a) { used[a] = true; long long s = in[a]; for (int i = 0; i < G[a].size(); ...
### Prompt Construct a CPP code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; vector<long long> vals; vector<long long> adj[200005]; vector<long long> subsum; vector<long long> maxsubsum; vector<long long> h; void dfs(long long u, long long p) { h[u] = h[p] + 1; subsum[u] = vals[u]; for (auto i : adj[u]) { if (i != p) { dfs(i, u); ...
### Prompt Generate a CPP solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& a) { a = 0; char c; bool _MINUS_ = false; while (!isdigit(c = getchar())) _MINUS_ |= c == '-'; do a = a * 10 + (c - '0'); while (isdigit(c = getchar())); if (_MINUS_) a *= -1; } string world[8] = {"U", "D", "R", "L", "...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 25; long long res = -1e18; int n, a[N]; long long s[N], f[N]; vector<int> G[N]; void dfs(int u, int p) { s[u] = a[u]; int p1, p2; p1 = p2 = 0; for (auto v : G[u]) { if (v == p) continue; dfs(v, u); f[u] = max(f[u], f[v]); s[u] += ...
### Prompt Generate a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for t...
#include <bits/stdc++.h> using namespace std; const int maxn(2e5 + 5); const long long inf(1e16 + 5); int head[maxn], node[maxn << 1], net[maxn << 1], n; long long val[maxn]; long long mx1[maxn], mx2[maxn], subMax[maxn]; void dfs(int k, int fa) { int nmd = 0; for (int i = head[k]; i; i = net[i]) { if (node[i] =...
### Prompt In cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[200000]; long long int a[200000]; long long int m = LLONG_MIN; long long int sz[200000]; long long int mx[200000]; void dfs(int cur, int pr) { sz[cur] = a[cur]; mx[cur] = LLONG_MIN; vector<long long int> q; for (int i = 0; i < g[cur].size(); i++...
### Prompt Create a solution in cpp for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 200005; long long int n, a[N], ans[N], dp[N], sum[N]; vector<long long int> adj[N]; long long int vis[N]; const long long int MIN_VAL = -2LL * 1000000000 - 5; void dfs(int v) { vis[v] = 1; long long int s = a[v], new_ans = MIN_V...
### Prompt Your task is to create a cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:10240000") using namespace std; const int MAXN = 200020; const long long MAX_INF = (long long)1e16; struct tedge { int t, next; } e[MAXN * 2]; int cnt = 0; long long ans = -MAX_INF; long long w[MAXN], dp[MAXN], val[MAXN]; int st[MAXN]; bool flag = false; void a...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897923846; const long long int MOD = 1000000007; const long long int N = 998244353; long long int power(long long int x, long long int n) { long long int res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD;...
### Prompt Please provide a cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n, a[200005]; vector<long long> adj[200005]; long long ans; bool Impossible; long long val[200005], Val[200005]; void dfs(long long u, long long par) { for (long long i = 0; i < adj[u].size(); i++) { long long v = adj[u][i]; ...
### Prompt In CPP, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long x[N]; vector<int> e[N]; long long m[N], t[N]; long long ans; int n; int u, v; bool was[N]; const long long inf = 1e18; void dfs(int id) { was[id] = 1; t[id] = x[id]; vector<long long> ch; for (int i = 0; i < e[id].size(); i++) { i...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000000000007LL; vector<vector<long long> > adj(200200); long long ans[200200], val[200200]; long long finalAns; void dfs(int u, int p) { long long mx1 = -MOD, mx2 = -MOD, sum = 0; for (int i = 0; i < adj[u].size(); i++) { int cur = adj[u][i...
### Prompt Please provide a Cpp coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; void In() { freopen("in.in", "r", stdin); } void Out() { freopen("out.out", "w", stdout); } const int N = 2e5 + 10; const int M = 3e5 + 10; const int Mbit = 1e6 + 10; const long long inf = 1e15; const long long mod = 1e9 + 7; long long val[N], dp[N], ans; vector<int> G[N]; ...
### Prompt Please create a solution in CPP to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 7; const int INF = 1e9; long long n, m, l, k, t, p, q, a, b, c, d, x, y, tmp = 0, ans = -1e18; vector<long long> edge[MAX]; long long pleasantness[MAX]; long long totalPleasantness[MAX]; long long maxPleasantness[MAX]; long long dfs(long long now, long...
### Prompt In Cpp, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = (1LL << 60); long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int N = 200005; vector<int> edge[N]; int v[N], in[N]; long long sum[N], dp[N], res = -1e18; int n; void dfs(int x, int f) { sum[x] = v[x]; long long fir = -1e18, sec = -1e18; for (int i = 0; i < edge[x].size(); i++) { int y = edge[x][i]; if (y == f) cont...
### Prompt Please create a solution in Cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; long long int mul(long long int x, long long int y) { long long int ans = 1; while (y > 0) { if (y & 1) ans = (ans * x) % -10000000000000007; x = (x * x) % -10000000000000007; y /= 2; } return ans; }; vector<vector<long long int> > v(200005); long long i...
### Prompt Please create a solution in cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const double eps = 0.0000001; const long long inf = -1 * (1e17 + 7); const int maxn = 200005; long long dp[maxn], m1, m2, ans, f[maxn], num[maxn]; int flag, vis[maxn]; vector<int> son[maxn]; void dfs(int u, int fa) { f[u] = num[u]; dp[u] = inf; long long tmp = inf; ...
### Prompt Please create a solution in Cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const long long INF = 1000000000000000000; long long a[maxn]; long long b[maxn]; vector<int> G[maxn]; long long dp[maxn]; long long dfs(int u, int v) { if (b[u] == -INF) { b[u] = a[u]; for (int i = 0; i < G[u].size(); ++i) { if ...
### Prompt Please create a solution in Cpp to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int MAXN = 222222; vector<int> E[MAXN]; int a[MAXN]; long long dp[MAXN]; long long s[MAXN]; int dad[MAXN]; long long ans = -(1LL << 60); void check_ans(int node) { vector<long long> best; for (int i = 0; i < E[node].size(); i++) { int to = E[node][i]; if (...
### Prompt Please provide a CPP coded solution to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They t...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<long long> dp; vector<pair<long long, long long>> ans; vector<bool> used; vector<long long> cost; int n; void dfs(int v) { used[v] = true; vector<long long> sons; sons.push_back(-1e18); sons.push_back(-1e18); for (int i = 0; i < g[v]....
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; map<long long, long long> mp; bool vis[200005]; vector<vector<int>> edges(2e5 + 5); long long n, u, v, ans, a[200005], s[200005]; long long dfs(int node) { long long sum = a[node]; vis[node] = 1; for (auto i : edges[node]) { if (!vis[i])...
### Prompt Develop a solution in cpp to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; struct nevun { long long sumtot, maxun, doima, ta; }; vector<int> g[200005]; long long val[200005], n; nevun tati[200005]; void setarb(int nod) { long long maxnow = (0 - (1LL << 60)); long long maxlo = (0 - (1LL << 60)); tati[nod].sumtot = val[nod]; tati[nod].maxu...
### Prompt Construct a Cpp code solution to the problem outlined: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long inf = 1LL << 62; long long a[N], b[N]; vector<int> tree[N]; void dfs(int u, int f) { b[u] = a[u]; for (int i = 0; i < (int)tree[u].size(); i++) { int v = tree[u][i]; if (v == f) continue; dfs(v, u); b[u] += b[v]; ...
### Prompt Create a solution in CPP for the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 400021; long long n, k; vector<vector<int> > adj(200006); vector<long long> a(200006); vector<long long> tot(200006, 0); long long ans = -1000000000000000; vector<long long> ansv(200006, (-1000000000000000)); int flag = 0; void dfs(int v, int p) { i...
### Prompt Your task is to create a Cpp solution to the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long INF = 1e17; long long sum[N], mx[N], ans = -INF, a[N]; vector<int> g[N]; void dfs(int v, int par) { vector<long long> d; for (auto u : g[v]) if (u != par) { dfs(u, v); sum[v] += sum[u]; d.push_back(mx[u]); ...
### Prompt In CPP, your task is to solve the following problem: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes fo...
#include <bits/stdc++.h> using namespace std; const long long INF = -1e18; long long ans = INF; int a[200100], p[200100]; vector<vector<int> > g(200100); vector<long long> sum(200100, 0), mx(200100, 0); void dfs(int v) { sum[v] = a[v]; mx[v] = INF; for (int i = 0; i < g[v].size(); ++i) if (p[v] != g[v][i]) { ...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; const int maxn = (2e5) + 10; const long long INF = -(2e11); vector<int> child[maxn]; int n; int a[maxn]; bool vis[maxn]; long long d[maxn], d2[maxn], ans; long long dfs(int cur) { d[cur] = a[cur]; vis[cur] = 1; for (int i = 0; i < child[cur].size(); i++) { int son...
### Prompt Develop a solution in CPP to the problem described below: Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n priz...
#include <bits/stdc++.h> using namespace std; int a[100005], vis[100005]; int main() { int n; scanf("%d", &n); int t = n; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); vis[a[i]] = 1; for (; vis[t] == 1; t--) printf("%d ", t); printf("\n"); } return 0; }
### Prompt In CPP, your task is to solve the following problem: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them ...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi...
### Prompt Your challenge is to write a CPP solution to the following problem: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snac...