feat: 975

This commit is contained in:
Barrett Ruth 2025-02-08 15:13:02 -05:00
parent 36120f2cec
commit 7440bc2937
11 changed files with 289 additions and 3 deletions

View file

@ -1,2 +1,9 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: Empty
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

8
codeforces/923/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -std=c++23
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -Wno-unknown-pragmas

View file

@ -1,4 +1,4 @@
-std=c++20
-std=c++23
-Wall
-Wextra
-Wshadow

64
codeforces/923/f.cc Normal file
View file

@ -0,0 +1,64 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static int sz(auto&& x) {
return static_cast<int>(x.size());
}
template <typename... Args>
void pr(std::format_string<Args...> fmt, Args&&... args) {
std::print(fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void prln(std::format_string<Args...> fmt, Args&&... args) {
std::println(fmt, std::forward<Args>(args)...);
}
using ll = long long;
using ld = long double;
template <typename T>
using vec = std::vector<T>;
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
void solve() {
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

44
codeforces/923/f.in Normal file
View file

@ -0,0 +1,44 @@
5
6 6
1 2 1
2 3 1
3 1 1
4 5 1
5 6 1
6 4 1
6 6
1 2 10
2 3 8
3 1 5
4 5 100
5 6 40
6 4 3
6 15
1 2 4
5 2 8
6 1 7
6 3 10
6 5 1
3 2 8
4 3 4
5 3 6
2 6 6
5 4 5
4 1 3
6 4 5
4 2 1
3 1 7
1 5 5
4 6
2 3 2
1 3 10
1 4 1
3 4 7
2 4 5
1 2 2
4 5
2 1 10
3 1 3
4 2 6
1 4 7
2 3 3

18
codeforces/923/f.out Normal file
View file

@ -0,0 +1,18 @@
u=6, v=4, w=1
1 3
6 4 5
u=6, v=4, w=3
3 3
6 4 5
u=6, v=5, w=1
1 4
6 5 2 1
u=1, v=4, w=1
1 4
1 4 3 2
u=3, v=1, w=3
3 3
3 1 2
[code]: 0
[time]: 4.04072 ms

8
codeforces/974/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -std=c++23
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -Wno-unknown-pragmas

View file

@ -1,4 +1,4 @@
-std=c++20
-std=c++23
-Wall
-Wextra
-Wshadow

100
codeforces/974/f.cc Normal file
View file

@ -0,0 +1,100 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename T>
constexpr T MIN = std::numeric_limits<T>::min();
template <typename T>
constexpr T MAX = std::numeric_limits<T>::max();
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static int sz(auto&& x) {
return static_cast<int>(x.size());
}
template <typename... Args>
void pr(std::format_string<Args...> fmt, Args&&... args) {
std::print(fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void prln(std::format_string<Args...> fmt, Args&&... args) {
std::println(fmt, std::forward<Args>(args)...);
}
using ll = long long;
using ld = long double;
template <typename T>
using vec = std::vector<T>;
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
vec<vec<ll>> tree;
vec<ll> a;
void solve() {
int n, c;
cin >> n >> c;
a.resize(n + 1);
for (int i = 1; i < n + 1; ++i) {
cin >> a[i];
}
tree.assign(n + 1, vec<ll>());
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
tree[u].push_back(v);
tree[v].push_back(u);
}
vec<vec<ll>> dp(n + 1, vec<ll>(2, 0));
auto dfs = [&](int u, int parent, auto&& self) -> void {
ll take = a[u] - c * tree[u].size();
ll dont = 0;
for (auto v : tree[u]) {
if (v == parent) continue;
self(v, u, self);
take += max(dp[v][0] + c, dp[v][1]);
dont += max(dp[v][0], dp[v][1] + c);
}
dp[u][0] = dont;
dp[u][1] = take;
};
dfs(1, -1, dfs);
prln("{}", max(dp[1][0], dp[1][1]));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

29
codeforces/974/f.in Normal file
View file

@ -0,0 +1,29 @@
5
3 1
2 3 1
1 2
2 3
3 1
3 6 3
1 2
2 3
3 1
-2 -3 -1
1 2
2 3
6 1
5 -4 3 6 7 3
4 1
5 1
3 5
3 6
1 2
8 1
3 5 2 7 8 5 -3 -4
7 3
1 8
4 3
3 5
7 6
8 7
2 1

8
codeforces/974/f.out Normal file
View file

@ -0,0 +1,8 @@
3
8
0
17
26
[code]: 0
[time]: 4.30703 ms