#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > g, nd, nk;
vector<long long> l, r, ans, col;
long long color = 0;
void paint(long long v) {
  if (col[v] == color) return;
  col[v] = color;
  for (long long i = 0; i < g[v].size(); i++) paint(g[v][i]);
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long nok(long long a, long long b) { return (a / gcd(a, b)) * b; }
bool dfs(long long v) {
  if (col[v] == 0) return true;
  col[v] = 0;
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    long long val = nk[v][i] / ans[v] * nd[v][i];
    if (val % l[to] != 0 || r[to] % val != 0 ||
        (ans[to] != -1 && ans[to] != val))
      return false;
    ans[to] = val;
    if (gcd(ans[v], ans[to]) != nd[v][i] || nok(ans[v], ans[to]) != nk[v][i])
      return false;
    if (!dfs(to)) return false;
  }
  return true;
}
int main() {
  long long n, m;
  cin >> n >> m;
  g.assign(n, vector<long long>());
  nd.assign(n, vector<long long>());
  nk.assign(n, vector<long long>());
  l.assign(n, 1);
  r.assign(n, 1);
  col.assign(n, 0);
  ans.assign(n, -1);
  long long i, j;
  for (i = 0; i < m; i++) {
    long long from, to, a, b;
    cin >> from >> to >> a >> b;
    from--;
    to--;
    g[from].push_back(to);
    nd[from].push_back(a);
    nk[from].push_back(b);
    g[to].push_back(from);
    nd[to].push_back(a);
    nk[to].push_back(b);
  }
  for (i = 0; i < n; i++) {
    if (g[i].size()) r[i] = nk[i][0];
    for (j = 0; j < g[i].size(); j++)
      r[i] = gcd(nk[i][j], r[i]), l[i] = nok(l[i], nd[i][j]);
  }
  for (i = 0; i < n; i++)
    if (col[i] == 0) {
      color++;
      paint(i);
    }
  for (j = 0; j < n; j++)
    if (ans[j] == -1)
      for (i = l[j]; i <= r[j]; i++)
        if (i % l[j] == 0 && r[j] % i == 0) {
          long long c = col[j];
          ans[j] = i;
          if (dfs(j)) break;
          for (long long l = 0; l < n; l++)
            if (col[l] == 0) {
              col[l] = c;
              ans[l] = -1;
            }
        }
  for (i = 0; i < n; i++)
    if (ans[i] == -1) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
  for (i = 0; i < n; i++) cout << ans[i] << ' ';
  return 0;
}
