#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, k, w, a, b;
int l[105], LINK[10005], ed[10005], v[105];
long long L[10005], G[10005], A[105], tmp, tmp2;
int B[10005], vis[105];
bool ok;
long long gcd(long long a, long long b) {
  if (a > b) return gcd(b, a);
  if (a == 0ll) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
  long long c = a * b;
  c /= gcd(a, b);
  return c;
}
void bd(int x, int y, int a, int b) {
  LINK[w] = l[x];
  l[x] = w;
  ed[w] = y;
  G[w] = (long long)(a);
  L[w] = (long long)(b);
  w++;
}
void DFS(int x) {
  v[x] = 1;
  vis[k++] = x;
  for (int i = l[x]; i != -1; i = LINK[i]) {
    if (v[ed[i]] == 1) {
      if (lcm(A[x], A[ed[i]]) != L[i] || gcd(A[x], A[ed[i]]) != G[i]) ok = 0;
      continue;
    }
    if (L[i] % A[x] != 0ll) {
      ok = 0;
      continue;
    }
    A[ed[i]] = (L[i] / A[x]) * G[i];
    DFS(ed[i]);
  }
}
int main() {
  memset(l, -1, sizeof(l));
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (m); i++) {
    scanf("%d %d %d %d", &x, &y, &a, &b);
    bd(x, y, a, b);
    bd(y, x, a, b);
  }
  memset(A, 0, sizeof(A));
  for (int i = (1); i <= (n); i++) {
    if (v[i]) continue;
    if (l[i] == -1) continue;
    ok = 1;
    for (int j = l[i]; j != -1; j = LINK[j]) {
      if (j == l[i])
        tmp = L[j];
      else
        tmp = gcd(tmp, L[j]);
    }
    for (int j = l[i]; j != -1; j = LINK[j]) {
      if (j == l[i])
        tmp2 = G[j];
      else
        tmp2 = lcm(tmp2, G[j]);
      if (tmp2 > tmp) {
        ok = 0;
        break;
      }
    }
    if (ok == 0) {
      printf("NO\n");
      return 0;
    }
    w = 0;
    for (int j = 1; j * j <= (int)(tmp); j++) {
      if ((int)(tmp) % j == 0) {
        if (j % (int)(tmp2) == 0) B[w++] = j;
        if (j != (int)(tmp) / j && ((int)(tmp) / j) % tmp2 == 0ll)
          B[w++] = (int)(tmp) / j;
      }
    }
    ok = 0;
    for (int j = (0); j < (w); j++) {
      A[i] = (long long)(B[j]);
      ok = 1;
      k = 0;
      DFS(i);
      if (ok == 1) break;
      for (int ii = (0); ii < (k); ii++) v[vis[ii]] = 0;
    }
    if (ok == 0) {
      printf("NO\n");
      return 0;
    }
  }
  for (int i = (1); i <= (n); i++)
    if (A[i] == 0ll) A[i] = 1ll;
  printf("YES\n");
  for (int i = (1); i <= (n); i++) printf("%I64d ", A[i]);
  printf("\n");
  return 0;
}
