Run ID Author Problem Lang Verdict Score Time Memory Code Length Submit Time
55473 wsad T4 回家 C++ Wrong Answer 20 1000 MS 2080 KB 1118 2022-08-18 11:15:35

Tests(1/5):


#include<bits/stdc++.h> using namespace std; const int N=100003; int liv[N],res[N],fa[N],son[N],hap[N]; queue<int> q; int Read(){ int sum=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') sum=sum*10+ch-'0',ch=getchar(); return sum*f; } int main(){ int T,n,m,x,y,k,happ; bool b; T=Read(); while(T--) { n=Read(),m=Read(); b=0; for(int i=1;i<=n;++i) liv[i]=Read(); for(int i=1;i<=n;++i) { res[i]=Read(); if(!liv[i] && res[i]) { cout<<"NO\n"; b=1; } } if(b) continue; for(int i=1;i<n;++i) { x=Read(),y=Read(); fa[y]=x; ++son[x]; } for(int i=1;i<=n;++i) if(!son[i]) q.push(i); while(!q.empty()) { k=q.front(); q.pop(); happ=(liv[k]+res[k])/2; if(happ<hap[k] || (liv[k]+res[k])&1) { cout<<"NO\n"; b=1; break; } hap[k]=0; liv[fa[k]]+=liv[k],hap[fa[k]]+=happ,--son[fa[k]]; if(!son[fa[k]]) q.push(fa[k]); } if(b) continue; cout<<"YES\n"; } return 0; }


Judgement Protocol: