#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int n, m;
int num[maxn];
int ans[maxn], lcmm[maxn];
int gcdd[maxn][maxn], lcm[maxn][maxn];
int ct = 0;
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int dfs(int i) {
  num[i] = ct;
  for (int j = 1; j <= n; j++)
    if (gcdd[i][j]) {
      if (num[j] == ct) {
        int d = gcd(ans[i], ans[j]);
        if (d != gcdd[i][j] || (long long)ans[i] * ans[j] / d != lcm[i][j])
          return 0;
      } else {
        if ((long long)gcdd[i][j] * lcm[i][j] % ans[i] != 0) return 0;
        if ((long long)gcdd[i][j] * lcm[i][j] / ans[i] > 1000000) return 0;
        ans[j] = (long long)gcdd[i][j] * lcm[i][j] / ans[i];
        if (gcd(ans[i], ans[j]) != gcdd[i][j]) return 0;
        if (dfs(j) == 0) return 0;
      }
    }
  return 1;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(gcdd, 0, sizeof(gcdd));
    memset(lcm, 0, sizeof(lcm));
    memset(ans, 0, sizeof(ans));
    memset(lcmm, 0, sizeof(lcmm));
    memset(num, 0, sizeof(num));
    int flag = 1;
    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      int c, d;
      scanf("%d%d", &c, &d);
      gcdd[b][a] = gcdd[a][b] = c;
      lcm[b][a] = lcm[a][b] = d;
      lcmm[a] = lcmm[b] = d;
    }
    for (int i = 1; i <= n; i++)
      if (num[i] == 0) {
        ans[i] = 1;
        ct++;
        while (ans[i] <= 1000000 && (lcmm[i] % ans[i] != 0 || !dfs(i))) {
          ct++;
          ans[i]++;
        }
        if (ans[i] > 1000000) {
          printf("NO\n");
          flag = 0;
          break;
        }
      }
    if (flag) {
      printf("YES\n");
      for (int i = 1; i <= n; i++)
        if (i == n)
          printf("%d\n", ans[i]);
        else
          printf("%d ", ans[i]);
    }
  }
  return 0;
}
