#include<iostream> #include<vector> #include<algorithm> #define maxn 200010 #define ll long long #define INF 1000000000 usingnamespacestd;
int n, m; int a[maxn], b[maxn];
structEdge { int to, next; } e[maxn * 2]; int c1, head[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; e[c1].next = head[u]; head[u] = c1++; }
int vis[maxn]; booldfs(int u, int d){ vis[u] = d; for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (vis[v] == d) return0; if (vis[v] == -1 && !dfs(v, d ^ 1)) return0; } return1; }
voidwork(){ cin >> n >> m; fill(head + 1, head + n + 1, -1); c1 = 0; fill(vis + 1, vis + n + 1, -1); ll sum = 0; for (int i = 1; i <= n; ++i) cin >> a[i], sum += a[i]; for (int i = 1; i <= n; ++i) cin >> b[i], sum -= b[i]; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; add_edge(x, y); add_edge(y, x); } if (sum & 1) returncout << "NO" << "\n", void(); if (!dfs(1, 0)) returncout << "YES" << "\n", void(); sum = 0; for (int i = 1; i <= n; ++i) if (vis[i]) sum += a[i] - b[i]; else sum -= a[i] - b[i]; cout << (sum == 0 ? "YES" : "NO") << "\n"; }