#include <bits/stdc++.h>
using namespace std;
long long Lcm[110][110], Gcd[110][110];
long long last[110], ans[110];
int n, m, u[110], v[110];
int tot = 0;
long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a % b); }
int check(int x, int y) {
  long long G = gcd(ans[x], ans[y]);
  long long L = (long long)ans[x] * (long long)ans[y] / (long long)G;
  if (G != Gcd[x][y] || L != Lcm[x][y]) return 0;
  return 1;
}
int dfs(int x) {
  u[x] = 1;
  v[x] = tot;
  for (int i = 1; i <= n; i++)
    if (Lcm[x][i])
      if (v[i] < tot) {
        ans[i] = Lcm[x][i] * Gcd[x][i] / ans[x];
        if (ans[i] == 0) return 0;
        if (!dfs(i)) return 0;
      } else if (!check(x, i))
        return 0;
  return 1;
}
int main() {
  cin >> n >> m;
  memset(Lcm, 0, sizeof(Lcm));
  memset(Gcd, 0, sizeof(Gcd));
  memset(last, 0, sizeof(last));
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long a, b;
    cin >> x >> y >> a >> b;
    Gcd[x][y] = Gcd[y][x] = a;
    Lcm[x][y] = Lcm[y][x] = b;
    last[x] = last[y] = b;
  }
  memset(u, 0, sizeof(u));
  memset(v, 0, sizeof(v));
  for (int i = 1; i <= n; i++)
    if (!u[i]) {
      if (!last[i]) {
        ans[i] = 1;
        continue;
      }
      int flag = 0;
      for (int j = 1; j * j <= last[i]; j++)
        if (last[i] % (long long)j == 0) {
          tot++;
          ans[i] = (long long)j;
          flag = max(flag, dfs(i));
          if (flag) break;
          tot++;
          ans[i] = last[i] / (long long)j;
          flag = max(flag, dfs(i));
          if (flag) break;
        }
      if (!flag) {
        cout << "NO" << endl;
        return 0;
      }
    }
  cout << "YES" << endl;
  for (int i = 1; i <= n; i++)
    if (i > 1)
      cout << " " << ans[i];
    else
      cout << ans[i];
  cout << endl;
  return 0;
}
