?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
188371901 |
Practice: DaiRuiChen007 |
1537F - 38 | C++14 (GCC 6-32) | Accepted | 234 ms | 12956 KB | 2023-01-08 04:02:15 | 2023-01-08 04:02:15 |
// LUOGU_RID: 98986219 #include<bits/stdc++.h> #define int long long using namespace std; const int MAXN=2e5+1; vector <int> G[MAXN]; bool vis[MAXN],col[MAXN],ok=true; int v[MAXN],t[MAXN]; inline void dfs(int p,bool c) { if(vis[p]) { if(c!=col[p]) ok=false; return ; } col[p]=c,vis[p]=true; for(int v:G[p]) dfs(v,c^1); } inline void solve() { int n,m,cnt=0; scanf("%lld%lld",&n,&m); for(int i=1;i<=n;++i) G[i].clear(),vis[i]=false; for(int i=1;i<=n;++i) scanf("%lld",&v[i]); for(int i=1;i<=n;++i) scanf("%lld",&t[i]); for(int i=1;i<=m;++i) { int u,v; scanf("%lld%lld",&u,&v); G[u].push_back(v); G[v].push_back(u); } ok=true,dfs(1,0); if(!ok) { for(int i=1;i<=n;++i) cnt+=t[i]-v[i]; puts(cnt%2==0?"YES":"NO"); return ; } for(int i=1;i<=n;++i) cnt+=(col[i])?(t[i]-v[i]):(v[i]-t[i]); puts(cnt==0?"YES":"NO"); } signed main() { int T; scanf("%lld",&T); while(T--) solve(); return 0; }
?
?
?
?