#include <bits/stdc++.h>
using namespace std;
int const max_n = 128;
int n, m;
long long gcd[max_n][max_n];
long long lcm[max_n][max_n];
long long val[max_n];
char vis[max_n], all[max_n];
long long Gcd(long long a, long long b) {
  if (a < b) return Gcd(b, a);
  if (!b) return a;
  return Gcd(b, a % b);
}
char check(int v) {
  vis[v] = 1;
  for (int w = 0; w < n; w++) {
    if (gcd[v][w]) {
      if (vis[w] && (val[v] * val[w] != gcd[v][w] * lcm[v][w] || !val[w] ||
                     Gcd(val[v], val[w]) != gcd[v][w])) {
        return 0;
      }
      if (!vis[w]) {
        if (gcd[v][w] * lcm[v][w] % val[v]) return 0;
        val[w] = (gcd[v][w] * lcm[v][w]) / val[v];
        if (!check(w)) return 0;
      }
    }
  }
  return 1;
}
char assign(int v) {
  for (int w = 0; w < n; w++) {
    if (gcd[v][w]) {
      for (val[v] = gcd[v][w]; val[v] <= lcm[v][w]; val[v] += gcd[v][w]) {
        memset(vis, 0, sizeof(vis));
        if (check(v)) {
          for (int u = 0; u < n; u++) all[u] |= vis[u];
          return 1;
        }
      }
      return 0;
    }
  }
  all[v] = 1;
  val[v] = 1;
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    cin >> gcd[a][b] >> lcm[a][b];
    if (lcm[a][b] % gcd[a][b] || lcm[a][b] < gcd[a][b]) {
      cout << "NO" << endl;
      return 0;
    }
    gcd[b][a] = gcd[a][b];
    lcm[b][a] = lcm[a][b];
  }
  for (int v = 0; v < n; v++) {
    if (!all[v] && !assign(v)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  for (int v = 0; v < n; v++) {
    cout << val[v];
    if (v + 1 < n)
      cout << ' ';
    else
      cout << endl;
  }
  return 0;
}
