#include <bits/stdc++.h>
using namespace std;
int n, m;
long long nod[101][101];
long long nok[101][101];
int g[101][101];
long long d[101];
long long z[101];
long long zz[101];
bool was[101];
bool done[101];
long long gcd(long long a, long long b) {
  if (b > a) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
bool dfs(int v) {
  was[v] = true;
  for (int u = 0; u < n; ++u) {
    if (g[v][u]) {
      if (!was[u]) {
        if ((nod[u][v] * nok[u][v]) % d[v] != 0) return false;
        d[u] = (nod[u][v] * nok[u][v]) / d[v];
        if (!dfs(u)) return false;
      } else {
        if (d[u] % nod[u][v] != 0) return false;
        if (d[v] % nod[u][v] != 0) return false;
        if (d[u] / nod[u][v] * d[v] != nok[u][v]) return false;
      }
    }
  }
  return true;
}
bool test() {
  for (int v = 0; v < n; ++v) {
    if (was[v]) {
      for (int u = 0; u < n; ++u) {
        if (was[u] && g[u][v]) {
          if (gcd(d[u], d[v]) != nod[u][v]) return false;
        }
      }
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    scanf("%lld %lld", &nod[u][v], &nok[u][v]);
    nod[v][u] = nod[u][v];
    nok[v][u] = nok[u][v];
    g[u][v] = g[v][u] = 1;
  }
  for (int v = 0; v < n; ++v) {
    z[v] = 1;
    zz[v] = 1;
    for (int u = 0; u < n; ++u) {
      if (g[v][u]) {
        z[v] = nok[u][v] / nod[u][v];
        zz[v] = nod[u][v];
        break;
      }
    }
  }
  memset(d, -1, sizeof(d));
  for (int v = 0; v < n; ++v) {
    if (!done[v]) {
      bool ok = false;
      for (long long k = 1; k * k <= z[v]; ++k) {
        if (z[v] % k == 0) {
          d[v] = k * zz[v];
          memset(was, false, sizeof(was));
          if (dfs(v)) {
            if (test()) {
              ok = true;
              for (int u = 0; u < n; ++u)
                if (was[u]) done[u] = true;
              break;
            }
          }
          d[v] = z[v] / k * zz[v];
          memset(was, false, sizeof(was));
          if (dfs(v)) {
            if (test()) {
              ok = true;
              for (int u = 0; u < n; ++u)
                if (was[u]) done[u] = true;
              break;
            }
          }
        }
      }
      if (!ok) {
        printf("NO");
        return 0;
      }
    }
  }
  printf("YES\n");
  for (int i = 0; i < n; ++i) printf("%lld ", d[i]);
  return 0;
}
