#include <bits/stdc++.h>
using namespace std;
int v[105], vt[105];
int fin[105];
int GCD[105][105], LCM[105][105];
vector<int> a[105];
int pl[105];
int u[105];
int n, m;
bool go(int x, int t, int p, int ucs) {
  u[x] = ucs;
  vt[x] = t;
  v[x] = pl[t];
  for (int i = 0; i < (int)a[x].size(); i++) {
    int y = a[x][i];
    int r = GCD[x][y], s = LCM[x][y];
    int cr = 0, cs = 0;
    while (r % p == 0) {
      ++cr;
      r /= p;
    }
    while (s % p == 0) {
      ++cs;
      s /= p;
    }
    if (u[y] == ucs) {
      if (!(cr == vt[x] && cs == vt[y]) && !(cr == vt[y] && cs == vt[x])) {
        return false;
      }
    } else if (cr == vt[x] && !go(y, cs, p, ucs))
      return false;
    else if (cr != vt[x] && cs == vt[x] && !go(y, cr, p, ucs))
      return false;
    else if (cr != vt[x] && cs != vt[x])
      return false;
  }
  return true;
}
bool test(int p) {
  for (int i = 1; i <= n; i++) u[i] = 0;
  pl[0] = 1;
  for (int i = 1; pl[i - 1] * 1LL * p <= 1000000; i++) pl[i] = pl[i - 1] * p;
  for (int i = 1; i <= n; i++) {
    if (!u[i]) {
      v[i] = 1;
      vt[i] = 0;
      if (a[i].size() == 0) continue;
      int y = a[i][0], r = GCD[i][y], s = LCM[i][y];
      int cr = 0, cs = 0;
      while (r % p == 0) {
        ++cr;
        ++cs;
        r /= p;
        s /= p;
      }
      while (s % p == 0) {
        ++cs;
        s /= p;
      }
      if (go(i, cr, p, 1) == true) continue;
      if (cr == cs) return false;
      if (go(i, cs, p, 2) == false) return false;
    }
  }
  for (int i = 1; i <= n; i++) fin[i] *= v[i];
  return true;
}
set<int> p;
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fin[i] = 1;
  int flag = 0;
  for (int i = 0; i < m; i++) {
    int x, y, g, l;
    scanf("%d%d%d%d", &x, &y, &g, &l);
    GCD[x][y] = GCD[y][x] = g;
    LCM[x][y] = LCM[y][x] = l;
    a[x].push_back(y);
    a[y].push_back(x);
    if (l % g != 0) flag = 1;
    for (int f = 2; f * f <= l; f++) {
      if (l % f == 0) {
        p.insert(f);
        while (l % f == 0) l /= f;
      }
    }
    if (l > 1) p.insert(l);
  }
  if (flag) {
    puts("NO");
    return 0;
  }
  for (set<int>::iterator it = p.begin(); it != p.end(); it++)
    if (test(*it) == false) {
      puts("NO");
      return 0;
    }
  puts("YES");
  for (int i = 1; i <= n; i++) printf("%d%c", fin[i], (i == n ? '\n' : ' '));
  return 0;
}
