#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge {
  int u, g, l;
  edge() { u = g = l = 0; }
  edge(int _u, int _g, int _l) {
    u = _u;
    g = _g;
    l = _l;
  }
};
vector<edge> e[105];
long long ans[105];
int p[105];
long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); }
int dfs(int k) {
  p[k] = 1;
  for (int i = 0; i < e[k].size(); ++i) {
    int u = e[k][i].u, g = e[k][i].g, l = e[k][i].l;
    if (l % ans[k] != 0) return 0;
    if (p[u] == 1) {
      if (1ll * l / ans[k] * g != ans[u] || gcd(ans[u], ans[k]) != g) {
        return 0;
      }
    } else {
      ans[u] = 1ll * l / ans[k] * g;
      if (gcd(ans[u], ans[k]) != g) return 0;
      if (dfs(u) == 0) return 0;
    }
  }
  return 1;
}
int ok(int k) {
  int mul = e[k][0].l / e[k][0].g;
  for (int i = 1; i * i <= mul; ++i) {
    if (mul % i != 0) continue;
    memset(p, 0, sizeof(p));
    ans[k] = i * e[k][0].g;
    if (dfs(k)) return 1;
    memset(p, 0, sizeof(p));
    ans[k] = mul / i * e[k][0].g;
    if (dfs(k)) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y, a, b;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d%d", &x, &y, &a, &b);
    e[x].push_back(edge(y, a, b));
    e[y].push_back(edge(x, a, b));
  }
  for (int i = 1; i <= n; ++i) {
    if (ans[i] > 0) continue;
    if (e[i].size() == 0) {
      ans[i] = 1;
      continue;
    }
    if (!ok(i)) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  for (int i = 1; i <= n; ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
