#include <bits/stdc++.h>
using namespace std;
long long nod(long long x, long long y) {
  if (y > x) swap(x, y);
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
long long nok(long long x, long long y) { return (x * y / nod(x, y)); }
int main() {
  long long n, m, nd, nk, i, j, l, d[105] = {0}, a[105] = {0}, md[105][105],
                                   mk[105][105];
  int x, y;
  vector<long long> s[105], v[105], tmp;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> nd >> nk;
    v[x].push_back(y);
    v[y].push_back(x);
    md[x][y] = nd;
    mk[x][y] = nk;
    md[y][x] = nd;
    mk[y][x] = nk;
    if (nk % nd != 0) {
      cout << "NO";
      return 0;
    }
    if (d[x] + d[y] == 0) {
      for (j = nd; j <= nk; j++) {
        if ((nk * nd) % j == 0) {
          s[x].push_back(j);
          s[x].push_back(nk * nd / j);
          s[y].push_back(j);
          s[y].push_back(nk * nd / j);
        }
      }
    } else if (d[x] && !d[y]) {
      tmp.clear();
      for (j = 0; j < s[x].size(); j++) {
        if ((nk * nd) % s[x][j] == 0) {
          tmp.push_back(s[x][j]);
          s[y].push_back((nk * nd) / s[x][j]);
        }
      }
      s[x] = tmp;
    } else if (d[y] && !d[x]) {
      tmp.clear();
      for (j = 0; j < s[y].size(); j++) {
        if ((nk * nd) % s[y][j] == 0) {
          tmp.push_back(s[y][j]);
          s[x].push_back((nk * nd) / s[y][j]);
        }
      }
      s[y] = tmp;
    } else {
      tmp.clear();
      for (j = 0; j < s[x].size(); j++) {
        if ((nk * nd) % s[x][j] == 0) tmp.push_back(s[x][j]);
      }
      s[x] = tmp;
      tmp.clear();
      for (j = 0; j < s[y].size(); j++) {
        if ((nk * nd) % s[y][j] == 0) tmp.push_back(s[y][j]);
      }
      s[y] = tmp;
    }
    d[x] = d[y] = 1;
    sort(s[x].begin(), s[x].end());
    sort(s[y].begin(), s[y].end());
  }
l:;
  for (i = 1; i <= n; i++) {
    if (d[i]) {
      if (a[i] >= s[i].size()) {
        if (i == 1) {
          cout << "NO";
          return 0;
        }
        for (j = 2; j <= n; j++) {
          a[j] = 0;
        }
        a[1]++;
      }
      for (j = 0; j < v[i].size(); j++) {
        if (v[i][j] < i) {
          if (s[i][a[i]] * s[v[i][j]][a[v[i][j]]] !=
                  mk[i][v[i][j]] * md[i][v[i][j]] ||
              nod(s[i][a[i]], s[v[i][j]][a[v[i][j]]]) != md[i][v[i][j]] ||
              nok(s[i][a[i]], s[v[i][j]][a[v[i][j]]]) != mk[i][v[i][j]]) {
            a[i]++;
            goto l;
          }
        } else {
          for (l = 0; l < s[v[i][j]].size(); l++) {
            if (s[i][a[i]] * s[v[i][j]][l] == mk[i][v[i][j]] * md[i][v[i][j]] &&
                nod(s[i][a[i]], s[v[i][j]][l]) == md[i][v[i][j]] &&
                nok(s[i][a[i]], s[v[i][j]][l]) == mk[i][v[i][j]])
              break;
          }
          if (l == s[v[i][j]].size()) {
            a[i]++;
            goto l;
          }
        }
      }
    }
  }
  cout << "YES" << endl;
  for (i = 1; i <= n; i++) {
    if (d[i])
      cout << s[i][a[i]] << " ";
    else
      cout << "1 ";
  }
  return 0;
}
