QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#415991 | #5418. Color the Tree | ocharin | WA | 40ms | 3796kb | C++23 | 1.1kb | 2024-05-21 13:55:32 | 2024-05-21 13:55:32 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e18;
void solve(){
int n;
cin>>n;
vector<int>a(n);
for(auto &i:a) cin>>i;
vector<vector<int>>e(n+1);
for(int i=1;i<n;++i){
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
vector<int>dep(n+1);
vector f(n+1,vector(n+1,0ll));
auto ma=dep;
auto dfs=[&](auto dfs,int u,int fa)->void{
ma[u]=dep[u]=dep[fa]+1;
for(auto v:e[u]){
if(v==fa) continue;
dfs(dfs,v,u);
ma[u]=ma[v];
}
f[u][0]=a[0];
vector<int>g(ma[u]-dep[u]+1);
for(int i=1;i<=ma[u]-dep[u];++i){
for(auto v:e[u]){
if(v==fa) continue;
if(dep[u]+i<=ma[v]) g[i]+=f[v][i-1];
}
f[u][i]=min(a[i],g[i]);
}
};
dfs(dfs,1,0);
int res=0;
for(int i=0;i<=ma[1];++i) res+=f[1][i];
cout<<res<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 4 10 15 40 1 1 2 2 3 2 4 5 10 5 1 100 1000 1 2 2 3 2 4 4 5 4 1000 200 10 8 1 2 2 3 3 4
output:
35 17 1218
result:
ok 3 number(s): "35 17 1218"
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 3796kb
input:
3000 54 43 44 11 49 17 14 7 30 35 12 34 14 15 8 29 47 30 31 39 17 26 23 26 45 34 50 49 13 35 18 29 15 13 44 47 5 22 20 19 46 30 22 26 13 47 46 43 27 48 48 13 14 30 44 1 2 1 3 2 4 3 5 4 6 2 7 4 8 1 9 3 10 1 11 8 12 2 13 9 14 1 15 1 16 15 17 15 18 7 19 1 20 19 21 13 22 10 23 17 24 9 25 9 26 24 27 8 28...
output:
98 96 44 159 60 85 84 39 74 39 115 49 98 49 93 38 50 59 44 82 81 99 55 61 74 149 56 99 35 30 46 70 64 106 103 79 116 64 33 60 62 112 131 71 79 98 62 43 43 52 56 26 71 41 42 86 90 68 23 88 78 43 96 43 132 30 65 74 74 86 58 77 44 58 101 104 77 55 64 61 96 32 119 101 75 60 36 77 78 103 16 103 66 46 42 ...
result:
wrong answer 1st numbers differ - expected: '180', found: '98'