#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m;
vector<tuple<int, int, int>> g[N];
int tin[N];
long long ans[N];
long long gcd(long long a, long long b) {
  while (b > 0) a %= b, swap(a, b);
  return a;
}
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool dfs(int from) {
  for (auto i : g[from]) {
    long long to, gg, l;
    tie(to, gg, l) = i;
    if (l % gg != 0) return false;
    if (tin[from] != tin[to]) {
      if (ans[from] % gg == 0 and l % ans[from] == 0) {
        ans[to] = (gg * l) / ans[from];
        tin[to] = tin[from];
        if (!dfs(to)) return false;
      } else
        return false;
    } else {
      if (gcd(ans[from], ans[to]) == gg and lcm(ans[from], ans[to]) == l)
        continue;
      else
        return false;
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v, gg, l;
    scanf("%d %d %d %d", &u, &v, &gg, &l);
    g[u].emplace_back(v, gg, l);
    g[v].emplace_back(u, gg, l);
  }
  bool ok = true;
  for (int i = 1; i <= n; ++i) {
    if (tin[i] == 0) {
      bool found = false;
      for (int j = 1; j <= 1e6; ++j) {
        tin[i] = j;
        ans[i] = j;
        if (dfs(i)) {
          found = true;
          break;
        }
      }
      if (!found) {
        ok = false;
        break;
      }
    }
  }
  if (!ok)
    puts("NO");
  else {
    puts("YES");
    for (int i = 1; i <= n; ++i) printf("%lld%c", ans[i], " \n"[i == n]);
  }
  return 0;
}
