QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699009 | #7684. Sweet Sugar | jiangzhihui# | WA | 118ms | 30472kb | C++14 | 1.1kb | 2024-11-01 23:44:13 | 2024-11-01 23:44:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
vector<int> gr[N];
int n,m,a[N];
int f[N][2];
int ans;
void dfs(int u,int fa){
f[u][a[u]&1]=a[u];
for(auto v:gr[u]){
if(v==fa)continue;
dfs(v,u);
int tmp[2]={f[u][0],f[u][1]};
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
if(f[u][i]!=-1&&f[v][j]!=-1)
tmp[(i+j)&1]=max(tmp[(i+j)&1],f[u][i]+f[v][j]);
}
}
f[u][0]=tmp[0];
f[u][1]=tmp[1];
}
if(f[u][m&1]>=m){
f[u][m&1]=-1;
ans++;
}
}
void solve(){
cin>>n>>m;
ans=0;
for(int i=1;i<=n;i++){
cin>>a[i];
gr[i].clear();
f[i][0]=f[i][1]=-1;
}
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
gr[u].push_back(v);
gr[v].push_back(u);
}
dfs(1,0);
cout<<ans<<'\n';
}
int main(){
//freopen("test.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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: 3ms
memory: 30472kb
input:
4 7 5 1 2 1 2 2 1 2 1 2 2 3 3 4 3 5 5 6 5 7 2 2 1 0 1 2 1 1 1 1 2 1
output:
2 0 1 0
result:
ok 4 number(s): "2 0 1 0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 29576kb
input:
12 1 1 0 1 1 1 1 1 2 1 2 0 1 2 1 1 2 2 1 3 0 1 3 1 1 3 2 1 2000000 0 1 2000000 1 1 2000000 2
output:
0 1 0 0 0 1 0 0 0 0 0 0
result:
ok 12 numbers
Test #3:
score: -100
Wrong Answer
time: 118ms
memory: 30392kb
input:
200000 5 2 1 1 0 0 1 2 4 5 2 4 1 3 2 5 1 0 0 0 0 0 5 1 1 2 3 2 5 4 5 3 1 0 0 0 1 1 4 4 2 3 4 5 2 5 9 1 0 0 0 2 4 3 2 1 3 1 5 1 5 3 0 1 1 0 1 5 4 2 1 4 3 5 1 5 1 0 2 1 1 1 5 3 2 4 3 4 1 4 5 1 1 0 1 1 0 1 5 4 2 1 3 5 2 5 7 0 2 1 1 2 5 1 2 3 2 5 5 4 5 5 0 1 0 1 0 2 4 4 3 5 2 1 5 5 1 0 0 1 0 1 4 1 4 5 2...
output:
2 0 0 0 1 3 3 0 0 2 0 0 2 1 0 0 2 1 0 3 0 1 0 2 1 0 0 0 0 0 1 2 0 0 2 2 0 1 0 0 0 0 3 3 0 0 1 1 3 1 2 0 4 0 1 1 0 1 0 0 1 5 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1 0 3 1 0 1 0 0 4 0 0 0 1 1 0 0 1 0 2 0 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 1 2 0 1 2 0 0 2 0 0 1 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '1', found: '2'