QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#668161 | #6438. Crystalfly | Kdlyh | WA | 0ms | 3548kb | C++20 | 1.5kb | 2024-10-23 12:02:03 | 2024-10-23 12:02:03 |
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] + a[0] << "\n";
}
signed main()
{
std::cin.tie(nullptr)->sync_with_stdio(false);
int _(1);
#ifdef tests
std::cin >> _;
#endif
while(_--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
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: 3548kb
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:
25 34 29 62 36 13 17 24 19 19
result:
wrong answer 2nd numbers differ - expected: '24', found: '34'