#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
inline bool read(T &n) {
  T x = 0, tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
  if (c == EOF) return false;
  if (c == '-') c = getchar(), tmp = -1;
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  n = x * tmp;
  return true;
}
template <class T>
inline void write(T n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  int len = 0, data[20];
  while (n) {
    data[len++] = n % 10;
    n /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(int a, int b) { return (long long)a * b / gcd(a, b); }
int N, M;
int cnt;
int ans[110];
int vis[110];
int g[110][110], l[110][110];
bool dfs(int u) {
  vis[u] = cnt;
  if (!ans[u]) return 0;
  for (int v = 1; v <= N; v++) {
    if (!g[u][v]) continue;
    if (vis[v] == cnt) {
      if (g[u][v] != gcd(ans[u], ans[v])) return 0;
      if (l[u][v] != lcm(ans[u], ans[v])) return 0;
    } else {
      ans[v] = (long long)g[u][v] * l[u][v] / ans[u];
      if (!dfs(v)) return 0;
    }
  }
  return 1;
}
bool solve(int u, int v) {
  for (int i = 1; i * i <= l[u][v]; i++) {
    if (l[u][v] % i) continue;
    cnt++;
    ans[u] = i;
    if (dfs(u)) return 1;
    cnt++;
    ans[u] = l[u][v] / i;
    if (dfs(u)) return 1;
  }
  return 0;
}
int main() {
  int u, v;
  read(N), read(M);
  for (int i = 0, j, k; i < M; i++) {
    read(u), read(v), read(j), read(k);
    g[u][v] = g[v][u] = j;
    l[u][v] = l[v][u] = k;
  }
  for (u = 1; u <= N; u++)
    for (v = u + 1; v <= N; v++) {
      if (ans[u]) continue;
      if (g[u][v] && !solve(u, v)) {
        puts("NO");
        return 0;
      }
    }
  puts("YES");
  for (u = 1; u <= N; u++) printf("%d ", ans[u] ? ans[u] : 1);
  return 0;
}
