QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#409105#7680. Subwaylight_ink_dots#WA 4ms40740kbC++141.6kb2024-05-11 18:53:242024-05-11 18:53:25

Judging History

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

  • [2024-05-11 18:53:25]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:40740kb
  • [2024-05-11 18:53:24]
  • 提交

answer

//ghost thread
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e6+100;
vector<int>v[N];
int n,k;
int dep[N],c[N],dad[N],w[N],up[N];
void dfs(int x,int fa){
    dep[x]=dep[fa]+1;dad[x]=fa;
    for(auto y:v[x]){
        if(y==fa) continue;
        dfs(y,x);
    }
}
queue<int>q;
int minsz[N],ext[N];
void solve(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        minsz[i]=1e9,w[i]=0,v[i].clear();
        ext[i]=0;
    }
    for(int i=1;i<=n;i++) cin>>c[i];
    for(int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int rt=0;
    for(int i=1;i<=n;i++){
        if(v[i].size()!=1) rt=i;
    }    
    dfs(rt,0);
    static int id[N];
    for(int i=1;i<=n;i++) id[i]=i;
    sort(id+1,id+1+n,[&](int u,int v){
        return dep[u]>dep[v];
    });
    int ans=0;
    for(int i=1;i<=n;i++){
        int x=id[i];
        for(int y:v[x]){
            if(y==dad[x]) continue;
            w[x]+=w[y]; 
            minsz[x]=min(minsz[x],minsz[y]);
        }
        w[x]+=c[x];
        if(c[x]==1) {
            minsz[x]=min(w[x],minsz[x]);
        }
        if((w[x]&1)==(k&1)&&w[x]>=k){
            minsz[x]=1e9;
            w[x]=0;ans++;up[x]=1e9;
            continue;
        }
        if((w[x]&1)!=(k&1)&&(w[x]-minsz[x])>=k){
            minsz[x]=1e9;
            w[x]=0;ans++;up[x]=1e9;
            continue;
        }
    }
    cout<<ans<<'\n';
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int T;cin>>T;
    while(T--) solve();

}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 40740kb

input:

3
1 2 1
2 1 2
3 3 2

output:

0
1
1

result:

wrong answer Integer parameter [name=minc] equals to 0, violates the range [1, 10000]