#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
long long g[100][100];
long long gcd[100][100];
long long lcm[100][100];
int w[100];
long long ans[100];
int n, m, col = 1;
long long Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; }
bool dfs(int u) {
  w[u] = col;
  for (int v = 0; v < n; v++)
    if (g[u][v]) {
      if (w[v] < col) {
        if (g[u][v] % ans[u])
          return false;
        else {
          ans[v] = g[u][v] / ans[u];
          long long q = Gcd(ans[v], ans[u]);
          if (q != gcd[u][v] || g[u][v] / q != lcm[u][v]) return false;
          if (!dfs(v)) return false;
        }
      } else {
        if (g[u][v] % ans[u])
          return false;
        else {
          long long q = Gcd(ans[v], ans[u]);
          if (q != gcd[u][v] || g[u][v] / q != lcm[u][v]) return false;
        }
      }
    }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    long long x, y;
    cin >> a >> b >> x >> y;
    a--;
    b--;
    if (y % x != 0) {
      cout << "NO" << endl;
      return 0;
    }
    gcd[b][a] = gcd[a][b] = x;
    lcm[b][a] = lcm[a][b] = y;
    g[b][a] = g[a][b] = x * y;
  }
  for (int i = 0; i < n; i++)
    if (w[i] == 0) {
      long long q = 0;
      for (int j = 0; j < n; j++)
        if (g[i][j] != 0) q = g[i][j];
      if (q == 0) {
        ans[i] = 1;
        continue;
      }
      long long p = (int)sqrt(q + 0.0) + 1;
      bool kpyto = false;
      for (int j = 1; j <= p; j++) {
        if (q % j == 0) {
          ans[i] = j;
          col++;
          if (!dfs(i)) {
            ;
            col++;
            ans[i] = q / j;
            if (dfs(i)) {
              kpyto = true;
              break;
            }
          } else {
            kpyto = true;
            break;
          }
        }
      }
      if (!kpyto) {
        cout << "NO" << endl;
        return 0;
      }
    }
  cout << "YES" << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}
