#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000;
class point {
 public:
  int id, val;
};
bool operator<(const point &a, const point &b) {
  if (a.val < b.val) return true;
  return false;
}
int n, m, i, j;
long long mark[101], r[101];
vector<int> x[101], p[101], q[101];
int gcd(int x, int y) {
  if (x > y) return gcd(y, x);
  if (x == 0) return y;
  return gcd(y % x, x);
}
bool dfs(int i, long long k) {
  r[i] = k;
  int j;
  for (j = 0; j < x[i].size(); j++)
    if (r[x[i][j]] == 0) {
      long long num = ((long long)q[i][j] * p[i][j]) / k;
      if ((long long)num * k != (long long)q[i][j] * p[i][j]) return false;
      if (num > maxn) return false;
      if (gcd(k, num) == p[i][j]) {
        if (dfs(x[i][j], num) == false) return false;
      } else
        return false;
    }
  return true;
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    int xx, pp, qq, yy;
    cin >> xx >> yy >> pp >> qq;
    x[xx].push_back(yy);
    p[xx].push_back(pp);
    q[xx].push_back(qq);
    x[yy].push_back(xx);
    p[yy].push_back(pp);
    q[yy].push_back(qq);
  }
  for (i = 1; i <= n; i++)
    if (mark[i] == 0) {
      int ans = 0;
      if (x[i].size() == 0) {
        mark[i] = 1;
        continue;
      }
      long long pr = q[i][0] / p[i][0];
      for (j = 1; j * j <= pr; j++)
        if (pr % j == 0) {
          memset(r, 0, sizeof(r));
          if (((long long)j * p[i][0] <= maxn) &&
              (dfs(i, j * p[i][0])) == true) {
            ans = 1;
            break;
          }
          memset(r, 0, sizeof(r));
          if (((long long)(pr / j) * p[i][0] <= maxn) &&
              (dfs(i, (pr / j) * p[i][0]) == true)) {
            ans = 1;
            break;
          }
        }
      if (ans == 0) {
        cout << "NO";
        return 0;
      }
      for (j = 1; j <= n; j++)
        if (r[j] > 0) mark[j] = r[j];
    }
  cout << "YES" << endl;
  for (i = 1; i <= n; i++) cout << mark[i] << " ";
  return 0;
}
