#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define pb push_back
#define vi vector<int>
#define vl vector<long long>
#define fast  \
  cin.tie(0); \
  ios::sync_with_stdio(false);
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, int>;

struct UnionFind {
  vector<int> rank, par;
  UnionFind() {}
  UnionFind(int n) {
    rank.resize(n, 0);
    par.resize(n, 0);
    for (int i = 0; i < n; i++) {
      makeTree(i);
    }
  }
  void makeTree(int x) {
    par[x] = x;
    rank[x] = 0;
  }
  bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
  bool unite(int x, int y) {
    x = findRoot(x);
    y = findRoot(y);
    if (x == y) return false;
    if (rank[x] > rank[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
    return true;
  }
  int findRoot(int x) {
    if (x != par[x]) {
      par[x] = findRoot(par[x]);
    }
    return par[x];
  }
};

int main() {
  fast;
  int n, m;
  cin >> n >> m;
  vl a(n), b(n);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  UnionFind s(n);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    s.unite(a - 1, b - 1);
  }
  map<int, vi> g;
  rep(i, 0, n) g[s.findRoot(i)].pb(i);
  for(auto i:g){
    ll cnt = 0;
    ll cnt2 = 0;
    for(auto j:i.se){
      cnt += a[j];
      cnt2 += b[j];
    }
    if(cnt != cnt2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)

const int maxn = 2e5 + 5;

struct edge{int to, w; edge *nxt;}*arc1[maxn], *arc2[maxn], pool[maxn << 2], *pt = pool;
int n, m;
int ans[maxn];
bool vis[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}

void addedge(edge *arc[], int u, int v, int w)
{
	*pt = (edge){v, w, arc[u]};
	arc[u] = pt++;
}

void gettr(int x)
{
	vis[x] = true;
	for (edge *e = arc1[x]; e; e = e->nxt)
		if (!vis[e->to])
		{
			addedge(arc2, x, e->to, e->w);
			gettr(e->to);
		}
}

void dfs(int x)
{
	for (edge *e = arc2[x]; e; e = e->nxt)
	{
		if (e->w != ans[x])
			ans[e->to] = e->w;
		else
			ans[e->to] = e->w - 1? e->w - 1 : e->w + 1;
		dfs(e->to);
	}
}

int main()
{
	n = getint(); m = getint();
	fo(i, 1, m)
	{
		int u, v, w;
		u = getint(); v = getint(); w = getint();
		addedge(arc1, u, v, w);
		addedge(arc1, v, u, w);
	}
	gettr(1);
	ans[1] = 1;
	dfs(1);
	fo(i, 1, n) printf("%d\n", ans[i]);
	return 0;
}