#include <bits/stdc++.h>
using namespace std;
const int M = 1e4 + 10;
const int N = 1e2 + 10;
long long n, m, u, v, tot, cnt, cnt2;
long long head[N], ver[M], last[M], mush[N], fa[N], rt[N], l[N], r[N];
long long Gcd[N][N], Lcm[N][N];
bool flag;
queue<long long> q;
long long find(long long x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
void add(long long x, long long y) {
  ver[++tot] = y;
  last[tot] = head[x];
  head[x] = tot;
}
long long gcd(long long x, long long y) {
  if (!x) return y;
  return gcd(y % x, x);
}
void bfs(long long s) {
  flag = 0;
  for (long long i = 1; i <= n; i++) {
    if (find(i) == s && i != s) mush[i] = 0;
  }
  while (!q.empty()) q.pop();
  q.push(s);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (long long i = head[x]; i; i = last[i]) {
      long long y = ver[i];
      if (mush[y]) continue;
      if (Gcd[x][y] * Lcm[x][y] % mush[x]) {
        flag = 1;
        return;
      }
      mush[y] = Gcd[x][y] * Lcm[x][y] / mush[x];
      if (gcd(mush[x], mush[y]) != Gcd[x][y] ||
          mush[x] * mush[y] / gcd(mush[x], mush[y]) != Lcm[x][y]) {
        mush[y] = 0;
        flag = 1;
        return;
      }
      q.push(y);
    }
  }
}
signed main() {
  memset(l, 0x3f, sizeof(l));
  scanf("%lld %lld", &n, &m);
  for (long long i = 1; i <= n; i++) fa[i] = i;
  for (long long i = 1; i <= m; i++) {
    scanf("%lld %lld", &u, &v);
    scanf("%lld %lld", &Gcd[u][v], &Lcm[u][v]);
    Gcd[v][u] = Gcd[u][v];
    Lcm[v][u] = Lcm[u][v];
    add(u, v);
    add(v, u);
    long long fu = find(u), fv = find(v);
    if (fu == fv) continue;
    fa[fu] = fv;
  }
  for (long long i = 1; i <= n; i++)
    if (fa[i] == i) rt[++cnt] = i;
  for (long long i = 1; i <= cnt; i++) {
    for (long long j = head[rt[i]]; j; j = last[j]) {
      long long y = ver[j];
      l[i] = min(l[i], Gcd[rt[i]][y]);
      r[i] = max(r[i], Lcm[rt[i]][y]);
    }
    if (l[i] == 0x3f3f3f3f3f3f3f3f) {
      mush[rt[i]] = 1;
      continue;
    }
    for (long long j = l[i]; j <= r[i]; j++) {
      mush[rt[i]] = j;
      bfs(rt[i]);
      if (!flag) break;
    }
  }
  for (long long i = 1; i <= n; i++) cnt2 += (mush[i] != 0);
  if (cnt2 == n) {
    puts("YES");
    for (long long i = 1; i <= n; i++) printf("%lld ", mush[i]);
    return 0;
  }
  puts("NO");
  return 0;
}
