#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int MAXX = 1000000;
int N, M;
int id;
vector<int> comp[MAXN];
bool vis[MAXN];
long long num[MAXN];
bool clash;
struct edge {
  int d;
  long long g, l;
  edge(int d, long long g, long long l) : d(d), g(g), l(l) {}
};
vector<edge> adj[MAXN];
int vcnt;
inline long long gcd(long long a, long long b) {
  long long t;
  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool dfs(int n, long long x) {
  if (x > MAXX || x < 1) {
    clash = true;
    return false;
  }
  vis[n] = true;
  num[n] = x;
  for (int i = 0, _i = adj[n].size(); i < _i; ++i) {
    long long calc = (adj[n][i].l * adj[n][i].g) / x;
    if (vis[adj[n][i].d]) {
      if (num[adj[n][i].d] != calc || calc < adj[n][i].g ||
          calc > adj[n][i].l || (calc % adj[n][i].g != 0) ||
          (adj[n][i].l % calc != 0) || gcd(calc, x) != adj[n][i].g ||
          lcm(calc, x) != adj[n][i].l) {
        clash = true;
        return false;
      }
    } else {
      if (!dfs(adj[n][i].d, calc)) return false;
    }
  }
  return true;
}
void go(int n, int c) {
  comp[c].push_back(n);
  vis[n] = true;
  for (int i = 0, _i = adj[n].size(); i < _i; ++i) {
    if (vis[adj[n][i].d]) continue;
    go(adj[n][i].d, c);
  }
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &N, &M);
  for (int i = 0, _i = M; i < _i; ++i) {
    int a, b, g, l;
    scanf("%d%d%d%d", &a, &b, &g, &l);
    adj[a].push_back(edge(b, g, l));
    adj[b].push_back(edge(a, g, l));
  }
  for (int i = (1), _i = (N); i <= _i; ++i)
    if (!vis[i]) go(i, id++);
  for (int i = 0, _i = id; i < _i; ++i) {
    int j;
    bool good = false;
    for (j = 1; j <= MAXX; j++) {
      clash = false;
      memset(vis, 0, sizeof vis);
      dfs(comp[i][0], (long long)j);
      if (!clash) {
        good = true;
        break;
      }
    }
    if (!good) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  for (int i = (1), _i = (N); i <= _i; ++i) {
    printf("%d ", num[i]);
  }
  return 0;
}
