#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
const int LOWER_LIMIT = 1;
const int UPPER_LIMIT = 1000000;
int n, m, len;
vector<int> a[MAXN], gcd[MAXN], lcm[MAXN];
long long values[MAXN];
int used[MAXN], q[MAXN];
int GCD(int a, int b) {
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int works(int startNode, int value) {
  memset(used, 0, sizeof(used));
  values[startNode] = value;
  used[startNode] = 1;
  len = 1;
  q[1] = startNode;
  for (int i = 1; i <= len; ++i) {
    int node = q[i];
    for (size_t j = 0; j < a[node].size(); ++j)
      if (!used[a[node][j]]) {
        used[a[node][j]] = 1;
        q[++len] = a[node][j];
        values[a[node][j]] =
            (long long)gcd[node][j] * lcm[node][j] / values[node];
        if (values[a[node][j]] < LOWER_LIMIT ||
            values[a[node][j]] > UPPER_LIMIT)
          return 0;
      }
  }
  for (int i = 1; i <= len; ++i)
    for (size_t j = 0; j < a[q[i]].size(); ++j) {
      if (GCD(values[q[i]], values[a[q[i]][j]]) != gcd[q[i]][j] ||
          (long long)values[q[i]] * values[a[q[i]][j]] /
                  GCD(values[q[i]], values[a[q[i]][j]]) !=
              lcm[q[i]][j])
        return 0;
    }
  return 1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y, g, l;
    scanf("%d %d %d %d", &x, &y, &g, &l);
    a[x].push_back(y);
    gcd[x].push_back(g);
    lcm[x].push_back(l);
    a[y].push_back(x);
    gcd[y].push_back(g);
    lcm[y].push_back(l);
  }
  int solution = 1;
  for (int i = 1; i <= n && solution; ++i)
    if (!values[i]) {
      values[i] = 1;
      if (a[i].size() == 0) {
        continue;
      }
      int rem = lcm[i][0] / gcd[i][0], found = 0;
      for (int d = 1; d * d <= rem; ++d)
        if (rem % d == 0) {
          if (works(i, d * gcd[i][0])) {
            found = 1;
            break;
          }
          if (works(i, gcd[i][0] * rem / d)) {
            found = 1;
            break;
          }
        }
      if (!found) solution = 0;
    }
  if (solution) {
    printf("YES\n");
    for (int i = 1; i < n; ++i) printf("%lld ", values[i]);
    printf("%lld\n", values[n]);
  } else {
    printf("NO\n");
  }
  return 0;
}
