#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
int n, m;
vector<pair<int, pair<int, int> > > adj[102];
bool czytaj_graf() {
  scanf("%d %d", &n, &m);
  for (int(k) = 0; (k) < (m); ++(k)) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (d % c) return false;
    adj[a].push_back(make_pair(b, make_pair(c, d)));
    adj[b].push_back(make_pair(a, make_pair(c, d)));
  }
  return true;
}
long long nwd(long long a, long long b) {
  if (b == 0) return a;
  return nwd(b, a % b);
}
long long nww(long long a, long long b) { return a / nwd(a, b) * b; }
int vis[102];
int num[102];
int numset[102];
int main() {
  if (!czytaj_graf()) {
    printf("NO");
    return 0;
  }
  int proba = 0;
  for (int(i) = 1; (i) <= (n); ++(i)) vis[i] = num[i] = numset[i] = 0;
  for (int(i) = 1; (i) <= (n); ++(i)) {
    if (vis[i]) continue;
    if (adj[i].empty()) {
      num[i] = 1;
      continue;
    }
    int gcd = adj[i][0].second.first, lcm = adj[i][0].second.second;
    int mnoznik;
    for (mnoznik = 1; mnoznik * gcd <= lcm; ++mnoznik) {
      if (lcm % (mnoznik * gcd)) continue;
      ++proba;
      num[i] = mnoznik * gcd;
      numset[i] = proba;
      bool broken = false;
      deque<int> q;
      q.push_back(i);
      while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        if (vis[v] == proba) continue;
        vis[v] = proba;
        for (typeof(adj[v].begin()) it = adj[v].begin(); it != adj[v].end();
             it++) {
          int w = it->first;
          int g = it->second.first;
          int l = it->second.second;
          int shouldbenumw = l / num[v] * g;
          if (nwd(num[v], shouldbenumw) != g ||
              nww(num[v], shouldbenumw) != l) {
            broken = true;
            goto breaker;
          }
          if (numset[w] == proba) {
            if (num[w] != shouldbenumw) {
              broken = true;
              goto breaker;
            }
          } else {
            num[w] = shouldbenumw;
            numset[w] = proba;
          }
          q.push_back(w);
        }
      }
    breaker:
      if (!broken) {
        break;
      }
    }
    if (mnoznik * gcd > lcm) {
      printf("NO");
      return 0;
    }
  }
  printf("YES\n");
  for (int(i) = 1; (i) <= (n); ++(i)) printf("%d ", num[i]);
}
