#include <bits/stdc++.h>
using namespace std;
long long d[311][311];
long long k[311][311];
int n, m;
long long a[3111];
int u[3111] = {0};
int h[3111] = {0};
int c = 0;
long long gcd(long long a, long long b) {
  long long c;
  while (a && b) {
    c = a % b;
    a = b;
    b = c;
  }
  return a + b;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b * 1LL); }
bool dfs(int x) {
  u[x] = c;
  if (!a[x]) return 0;
  for (int i = 1; i <= n; i++) {
    if (d[x][i] != -1) {
      if (u[i] == c) {
        if (gcd(a[x], a[i]) != d[x][i]) return 0;
        if (lcm(a[x], a[i]) != k[x][i]) return 0;
      } else {
        a[i] = d[x][i] * k[x][i] / a[x];
        if (!dfs(i)) return 0;
      }
    }
  }
  return 1;
}
bool ok(int x, int y) {
  for (int i = 1; i * i <= k[x][y]; i++) {
    if (k[x][y] % i == 0) {
      c++;
      a[x] = i;
      if (dfs(x)) return 1;
      c++;
      a[x] = k[x][y] / i;
      if (dfs(x)) return 1;
    }
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) d[i][j] = k[i][j] = -1;
    a[i] = -1;
  }
  int x, y, nd, nk;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> nd >> nk;
    d[x][y] = nd;
    d[y][x] = nd;
    k[x][y] = k[y][x] = nk;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] == -1)
      for (int j = i + 1; j <= n; j++) {
        if (d[i][j] != -1) {
          if (!ok(i, j)) {
            cout << "NO";
            return 0;
          }
          break;
        }
      }
  cout << "YES\n";
  for (int i = 1; i <= n; i++)
    if (a[i] == -1)
      cout << 1 << " ";
    else
      cout << a[i] << " ";
  return 0;
}
