diff --git a/codeforces/923/.clang-format b/codeforces/923/.clang-format index 5625628..e7350c4 100644 --- a/codeforces/923/.clang-format +++ b/codeforces/923/.clang-format @@ -1,2 +1,9 @@ BasedOnStyle: Google -AllowShortFunctionsOnASingleLine: Empty +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/923/.clangd b/codeforces/923/.clangd new file mode 100644 index 0000000..4fab872 --- /dev/null +++ b/codeforces/923/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++23 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/923/compile_flags.txt b/codeforces/923/compile_flags.txt index ebd5be8..6817adc 100644 --- a/codeforces/923/compile_flags.txt +++ b/codeforces/923/compile_flags.txt @@ -1,4 +1,4 @@ --std=c++20 +-std=c++23 -Wall -Wextra -Wshadow diff --git a/codeforces/923/f.cc b/codeforces/923/f.cc new file mode 100644 index 0000000..854ed1a --- /dev/null +++ b/codeforces/923/f.cc @@ -0,0 +1,64 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static int sz(auto&& x) { + return static_cast(x.size()); +} + + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#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; +} diff --git a/codeforces/923/f.in b/codeforces/923/f.in new file mode 100644 index 0000000..5902be2 --- /dev/null +++ b/codeforces/923/f.in @@ -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 diff --git a/codeforces/923/f.out b/codeforces/923/f.out new file mode 100644 index 0000000..a119f43 --- /dev/null +++ b/codeforces/923/f.out @@ -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 \ No newline at end of file diff --git a/codeforces/974/.clangd b/codeforces/974/.clangd new file mode 100644 index 0000000..4fab872 --- /dev/null +++ b/codeforces/974/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++23 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/974/compile_flags.txt b/codeforces/974/compile_flags.txt index ebd5be8..6817adc 100644 --- a/codeforces/974/compile_flags.txt +++ b/codeforces/974/compile_flags.txt @@ -1,4 +1,4 @@ --std=c++20 +-std=c++23 -Wall -Wextra -Wshadow diff --git a/codeforces/974/f.cc b/codeforces/974/f.cc new file mode 100644 index 0000000..6d89832 --- /dev/null +++ b/codeforces/974/f.cc @@ -0,0 +1,100 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static int sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#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> tree; +vec 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()); + + 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> dp(n + 1, vec(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; +} diff --git a/codeforces/974/f.in b/codeforces/974/f.in new file mode 100644 index 0000000..c0dd4e7 --- /dev/null +++ b/codeforces/974/f.in @@ -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 diff --git a/codeforces/974/f.out b/codeforces/974/f.out new file mode 100644 index 0000000..eafd074 --- /dev/null +++ b/codeforces/974/f.out @@ -0,0 +1,8 @@ +3 +8 +0 +17 +26 + +[code]: 0 +[time]: 4.30703 ms \ No newline at end of file