QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557329#7684. Sweet Sugarrotcar07Compile Error//C++14791b2024-09-11 09:00:082024-09-11 09:00:08

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 09:00:08]
  • 评测
  • [2024-09-11 09:00:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e6+5;
int n,k,a[maxn];
int ans,dp[maxn][2];
vector<int> e[maxn];
bool dfs(int p,int f){
    dp[p][0]=dp[p][1]=-1e9;
    dp[p][a[p]&1]=a[p];
    for(auto x:e[p])if(x!=f){
        if(dfs(x,p)) continue;
        int z[2]={-1e9,-1e9};
        for(int a:{0,1})for(int b:{0,1}) z[a^b]=max(z[a^b],dp[p][a]+dp[x][b]);
        dp[p][0]=z[0],dp[p][1]=z[1];
    }
    if(dp[p][k&1]>=k) return ++ans;
    else return 0;
}
inline void solve(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) e[i].clear();
    for(int i=1,u,v;i<n;i++) cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
    ans=0;dfs(1,0);
    cout<<ans<<'\n';
}
int main(){
    int t;cin>>t;
    while(t--) solve();
}

Details

answer.code: In function ‘bool dfs(int, int)’:
answer.code:12:19: error: narrowing conversion of ‘-1.0e+9’ from ‘double’ to ‘int’ [-Wnarrowing]
   12 |         int z[2]={-1e9,-1e9};
      |                   ^~~~
answer.code:12:24: error: narrowing conversion of ‘-1.0e+9’ from ‘double’ to ‘int’ [-Wnarrowing]
   12 |         int z[2]={-1e9,-1e9};
      |                        ^~~~