#include <bits/stdc++.h>
using namespace std;
template <typename T>
int size(T& a) {
  return (int)a.size();
}
template <typename T>
T sqr(T a) {
  return a * a;
}
int to[10000];
int nxt[10000];
int head[110];
int from[11000];
long long nod[10000];
long long nok[10000];
int e = 0;
int deg[110];
long long ans[110];
void ae(int u, int v, int nd, int nk) {
  to[e] = v, from[e] = u, nod[e] = nd, nok[e] = nk, nxt[e] = head[u],
  head[u] = e++;
  deg[u]++;
}
int color[110];
void init() {
  memset((deg), 0, sizeof(deg));
  memset((head), 255, sizeof(head));
}
bool used[110];
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool check(int cur) {
  if (used[cur]) return true;
  used[cur] = true;
  bool ok = true;
  for (int i = head[cur]; ok && i >= 0; i = nxt[i]) {
    if ((long long)nod[i] * nok[i] % ans[cur] != 0) {
      return false;
    }
    ans[to[i]] = (long long)nod[i] * nok[i] / ans[cur];
    ok &= check(to[i]);
  }
  return ok;
}
bool yet(int cur) {
  if (used[cur]) return true;
  used[cur] = true;
  for (int i = head[cur]; i >= 0; i = nxt[i]) {
    if (gcd(ans[cur], ans[to[i]]) != nod[i] ||
        lcm(ans[cur], ans[to[i]]) != nok[i])
      return false;
  }
  return true;
}
void col(int cur) {
  if (color[cur] == -1) return;
  color[cur] = 1;
  for (int i = head[cur]; i >= 0; i = nxt[i]) {
    col(to[i]);
  }
}
int main() {
  init();
  int n, m;
  scanf("%d%d", &n, &m);
  for (int(i) = (0); (i) < (m); ++i) {
    int u, v, nd, nk;
    cin >> u >> v >> nd >> nk;
    --u, --v;
    ae(u, v, nd, nk);
    ae(v, u, nd, nk);
  }
  memset((color), 255, sizeof(color));
  for (int i = 0; i < n; ++i) {
    if (color[i] != -1) continue;
    if (deg[i] == 0) {
      color[i] = 1;
      ans[i] = 1;
      continue;
    }
    int A = nod[head[i]], B = nok[head[i]], t = to[head[i]];
    long long m = (long long)A * B;
    bool f = false;
    for (long long d = 1; !f && d * d <= m; d++) {
      if (m % d == 0) {
        if (f) break;
        long long a = d, b = m / d;
        ans[i] = a;
        ans[t] = b;
        memset((used), false, sizeof(used));
        if (check(i)) {
          memset((used), false, sizeof(used));
          if (yet(i)) {
            f = true;
            col(i);
            break;
          }
        }
        if (f) break;
        a = m / d, b = d;
        ans[i] = a;
        ans[t] = b;
        memset((used), false, sizeof(used));
        if (check(i)) {
          memset((used), false, sizeof(used));
          if (yet(i)) {
            f = true;
            col(i);
            break;
          }
        }
      }
    }
    if (!f) {
      printf("NO");
      exit(0);
    }
  }
  printf("YES\n");
  for (int(i) = (0); (i) < (n); ++i) cout << ans[i] << " ";
  return 0;
}
