#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, nd, nk, col;
int val[200], w[200];
int a[200][200], b[200][200];
void nosol() {
  puts("NO");
  exit(0);
}
int gcd(int a, int b) {
  if (!a) return b;
  return gcd(b % a, a);
}
long long nok(int a, int b) { return a * 1ll * b / gcd(a, b); }
bool dfs(int u) {
  w[u] = col;
  if (!val[u]) return 0;
  for (int i = 0; i < n; i++)
    if (a[u][i])
      if (w[i] == col) {
        if (gcd(val[i], val[u]) != a[i][u]) return 0;
        if (nok(val[i], val[u]) != b[i][u]) return 0;
      } else {
        val[i] = a[u][i] * 1ll * b[u][i] / val[u];
        if (!dfs(i)) return 0;
      }
  return 1;
}
bool paint(int u, int v) {
  for (int i = 1; i * i <= b[u][v]; i++)
    if (b[u][v] % i == 0) {
      col++;
      val[u] = i;
      if (dfs(u)) return 1;
      col++;
      val[u] = b[u][v] / i;
      if (dfs(u)) return 1;
    }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) val[i] = -1;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &x, &y, &nd, &nk);
    x--;
    y--;
    a[x][y] = a[y][x] = nd;
    b[x][y] = b[y][x] = nk;
  }
  for (int i = 0; i < n; i++)
    if (val[i] == -1)
      for (int j = i + 1; j < n; j++)
        if (a[i][j]) {
          if (!paint(i, j)) nosol();
          break;
        }
  puts("YES");
  for (int i = 0; i < n; i++)
    printf("%d%c", (val[i] == -1 ? 1 : val[i]), i == n - 1 ? '\n' : ' ');
  return 0;
}
