QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658162 | #6438. Crystalfly | wzl19371 | WA | 1ms | 6264kb | C++20 | 1.6kb | 2024-10-19 16:17:20 | 2024-10-19 16:17:20 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
typedef long long ll;
constexpr int maxn = 2e5+10;
constexpr ll mod = 998244353;
int head[maxn], ct;
struct Edge {
int to, nxt;
} g[maxn << 1];
void add(int x, int y) {
g[++ct] = {y, head[x]};
head[x] = ct;
}
void solve() {
ct = 0;
memset(head, 0, sizeof(head));
int n; cin >> n;
int a[n+5]; rep(i,1,n) cin >> a[i];
int t[n+5]; rep(i,1,n) cin >> t[i];
for(int i=1;i<=n-1;i++) {
int x, y; cin >> x >> y;
add(x, y);
add(y, x);
}
ll f[n+5] = {};
f[0] = a[1];
function<void(int,int)> dfs = [&](int x, int fa) -> void {
int mx3 = 0, mx3i, mx = 0;
for(int i=head[x];i;i=g[i].nxt) {
if(g[i].to == fa) continue;
if(t[g[i].to] == 3) {
if(mx3 < a[g[i].to]) {
mx3 = a[g[i].to];
mx3i = g[i].to;
}
}
}
for(int i=head[x];i;i=g[i].nxt) {
if(g[i].to == fa) continue;
if(g[i].to == mx3i) continue;
if(mx < a[g[i].to]) {
mx = a[g[i].to];
}
}
f[x] = f[fa] + mx3 + mx;
for(int i=head[x];i;i=g[i].nxt) {
if(g[i].to == fa) continue;
dfs(g[i].to, x);
}
};
dfs(1, 0);
ll out = 0;
for(int i=1;i<=n;i++)
out = max(out, f[i]);
cout << out << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6264kb
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: 1ms
memory: 4268kb
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 24 24 47 31 13 16 28 19 19
result:
wrong answer 4th numbers differ - expected: '56', found: '47'