QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#668157 | #6438. Crystalfly | Kdlyh | WA | 0ms | 3764kb | C++20 | 1.5kb | 2024-10-23 12:00:01 | 2024-10-23 12:00:06 |
Judging History
answer
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 42
#endif
using i64 = long long;
namespace ranges = std::ranges;
//ti = 3, 可以多选一个旁支
//ti < 3, 只能选一条路
void solve()
{
#define tests
int n; std::cin >> n; std::vector<int> a(n); std::vector<int> t(n); for (auto& ai : a) {std::cin >> ai;} for (auto& ti : t) {std::cin >> ti;}
std::vector adj(n, std::vector<int>()); for (int i = 0, u, v; i + 1 < n; i++) {std::cin >> u >> v; --u; --v; adj[u].push_back(v); adj[v].push_back(u);}
std::vector<i64> dp(n);
auto dfs = [&](auto self, int now, int fa) -> void {
std::set<std::pair<int, int>> S; for (auto& to : adj[now]) if (to != fa) {S.emplace(a[to], to);}
auto get_max_except = [&](int id) {auto it{S.rbegin()}; if (it->second == id) {it++;} return it->first;};
for (auto& to : adj[now]) if (to != fa) {
self(self, to, now);
if (t[to] < 3) {
dp[now] = std::max(dp[now], dp[to] + a[to]);
dp[now] = std::max(dp[now], dp[to] + get_max_except(to));
} else {
dp[now] = std::max(dp[now], dp[to] + a[to] + get_max_except(to));
}
}
};
dfs(dfs, 0, -1);
std::cout << dp[0] + 1 << "\n";
}
signed main()
{
std::cin.tie(nullptr)->sync_with_stdio(false);
int _(1);
#ifdef tests
std::cin >> _;
#endif
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3764kb
input:
2 5 1 10 100 1000 10000 1 2 1 1 1 1 2 1 3 2 4 2 5 5 1 10 100 1000 10000 1 3 1 1 1 1 2 1 3 2 4 2 5
output:
10101 10111
result:
ok 2 number(s): "10101 10111"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3508kb
input:
10 6 8 1 1 5 8 9 2 1 2 2 2 2 1 2 2 3 2 4 1 5 2 6 6 6 4 4 1 3 6 2 1 3 3 3 3 1 2 1 3 3 4 4 5 5 6 6 10 5 1 8 5 1 1 3 1 2 2 2 1 2 2 3 2 4 2 5 3 6 10 6 8 8 9 6 9 5 6 6 4 2 1 3 3 2 2 2 2 3 1 1 2 1 3 3 4 4 5 5 6 4 7 2 8 7 9 9 10 7 10 9 1 5 7 5 4 1 1 1 2 1 3 2 1 2 1 3 3 4 3 5 5 6 1 7 5 7 1 1 4 2 3 1 3 2 2 1...
output:
18 29 20 57 27 7 16 17 12 19
result:
wrong answer 1st numbers differ - expected: '25', found: '18'