QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666060 | #6438. Crystalfly | bhscer | WA | 2ms | 8332kb | C++17 | 1.9kb | 2024-10-22 16:26:35 | 2024-10-22 16:26:54 |
Judging History
answer
#include<bits/stdc++.h>
#define ls p*2
#define rs p*2+1
#define x first
#define y second
#define endl '\n'
using namespace std;
mt19937 rnd(time(0));
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<LL,LL>PII;
typedef pair<double,double>PDD;
const double PI=acos(-1);
const int N=1e5+10,M=2e6,MOD=998244353,NN=1e6+10;
int T;
int n;
LL a[N];
LL dp[N];
LL DP[N];
PII MAX[N][2];
int t[N];
vector<int>vec[N];
void check(LL x,LL y,int u){
PII cur={x,y};
if(cur.first>MAX[u][0].first){
MAX[u][1]=MAX[u][0];
MAX[u][0]=cur;
}else if(cur.first>MAX[u][1].first){
MAX[u][0]=cur;
}
}
void dfs(int u,int pa){
for(auto e:vec[u]){
if(e==pa) continue;
dfs(e,u);
//check(a[e],t[e],u);
DP[u]+=dp[e];
}
//找t==3时的最大值,找
for(auto e:vec[u]){
if(e==pa) continue;
dp[u]=max(dp[u],DP[u]+a[e]);
check(a[e]-(dp[e]-DP[e]),e,u);
}
for(auto e:vec[u]){
if(e==pa) continue;
if(t[e]==3){
if(MAX[u][0].y==e){
dp[u]=max(dp[u],DP[u]+a[e]+MAX[u][1].x);
}else{
dp[u]=max(dp[u],DP[u]+a[e]+MAX[u][0].x);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>t[i];
}
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
vec[u].push_back(v);
vec[v].push_back(u);
}
dfs(1,0);
cout<<a[1]+dp[1]<<endl;
for(int i=1;i<=n;i++){
t[i]=0;
dp[i]=0;
DP[i]=0;
vec[i].clear();
}
}
}
//
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6532kb
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: 2ms
memory: 8332kb
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 20 27 57 37 18 22 28 19 19
result:
wrong answer 2nd numbers differ - expected: '24', found: '20'