#include <bits/stdc++.h>
using namespace std;
const int MaxN = 105;
struct Edge {
  int v;
  long long gcd, lcm;
  Edge *nxt;
} buf[MaxN * MaxN * 2], *g[MaxN], *p;
void add(int u, int v, int gcd, int lcm) {
  p->v = v;
  p->gcd = gcd;
  p->lcm = lcm;
  p->nxt = g[u];
  g[u] = p++;
}
int n, m, g1[MaxN], l1[MaxN];
bool ok;
long long ax[MaxN];
bool vst[MaxN];
long long Gcd(long long x, long long y) {
  if (x < y) swap(x, y);
  return y == 0 ? x : Gcd(y, x % y);
}
void dfs(int u, long long x) {
  ax[u] = x;
  vst[u] = 1;
  if (!ok) return;
  for (Edge *now = g[u]; now; now = now->nxt) {
    int v = now->v, g = now->gcd, l = now->lcm;
    if (vst[v]) {
      long long G = Gcd(ax[u], ax[v]);
      if (G != (long long)g || ax[u] * ax[v] / G != (long long)l) {
        ok = 0;
      }
    } else {
      x = (long long)g * l / ax[u];
      ax[v] = x;
      long long G = Gcd(ax[u], ax[v]);
      if (G != (long long)g || ax[u] * ax[v] / G != (long long)l) {
        ok = 0;
      }
      dfs(v, x);
    }
  }
}
int Set[MaxN];
int find(int x) {
  if (Set[x] == x) return x;
  return Set[x] = find(Set[x]);
}
void sol() {
  if (m == 0) {
    puts("YES");
    for (int i = 0; i < n; i++) printf("1%c", i == n - 1 ? '\n' : ' ');
    return;
  }
  bool get = 0, all = 1;
  for (int k = 1; k <= n; k++)
    if (find(k) == k) {
      get = 0;
      for (int i = 1; i <= l1[k] / g1[k]; i++)
        if (l1[k] / g1[k] % i == 0 && Gcd(l1[k] / g1[k] / i, i) == 1LL) {
          memset(vst, 0, sizeof(vst));
          ok = 1;
          dfs(k, (long long)i * g1[k]);
          if (ok) {
            get = 1;
            break;
          }
        }
      if (!get) all = 0;
    }
  if (!all)
    puts("NO");
  else {
    puts("YES");
    for (int i = 1; i <= n; i++) {
      printf("%I64d", ax[i]);
      printf("%c", i == n ? '\n' : ' ');
    }
  }
}
struct EDGE {
  int x, y, g, l;
} e[MaxN * MaxN];
int main() {
  p = buf;
  memset(g, 0, sizeof(g));
  scanf("%d%d", &n, &m);
  ok = 1;
  for (int i = 1; i <= n; i++) {
    g1[i] = l1[i] = 1;
    Set[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int x, y, a, b;
    scanf("%d%d%d%d", &x, &y, &a, &b);
    e[i].x = x;
    e[i].y = y;
    e[i].g = a;
    e[i].l = b;
    Set[find(x)] = find(y);
    add(x, y, a, b);
    add(y, x, a, b);
    if (b % a) ok = 0;
  }
  if (!ok) {
    puts("NO");
    return 0;
  }
  for (int i = 0; i < m; i++)
    if (e[i].x == find(e[i].x) || e[i].y == find(e[i].x)) {
      g1[find(e[i].x)] = e[i].g;
      l1[find(e[i].x)] = e[i].l;
    }
  sol();
  return 0;
}
