#include <bits/stdc++.h>
using namespace std;
struct arc {
  int f, s, prev;
  long long nok, nod;
} arr[20000];
bool was[105];
long long value[105];
int beg[105];
int kol = 0;
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
void add_arc(int f, int s, int nok, int nod) {
  arr[kol].f = f;
  arr[kol].s = s;
  arr[kol].nod = nod;
  arr[kol].nok = nok;
  arr[kol].prev = beg[f];
  beg[f] = kol++;
  arr[kol].s = f;
  arr[kol].f = s;
  arr[kol].nod = nod;
  arr[kol].nok = nok;
  arr[kol].prev = beg[s];
  beg[s] = kol++;
}
bool DFS(int pos) {
  was[pos] = true;
  for (int i = beg[pos]; i != -1; i = arr[i].prev) {
    if (value[pos] % arr[i].nod != 0 || arr[i].nok % value[pos] != 0) {
      return false;
    } else if (was[arr[i].s]) {
      if (value[arr[i].s] / arr[i].nod * value[pos] != arr[i].nok ||
          value[arr[i].s] % arr[i].nod != 0) {
        return false;
      } else if (gcd(value[arr[i].s], value[pos]) != arr[i].nod) {
        return false;
      }
    } else {
      value[arr[i].s] = arr[i].nok / value[pos] * arr[i].nod;
      if (gcd(value[arr[i].s], value[pos]) != arr[i].nod) {
        return false;
      }
      if (!DFS(arr[i].s)) {
        return false;
      }
    }
  }
  return true;
}
int main() {
  memset(beg, -1, sizeof beg);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int f, s, nok, nod;
    cin >> f >> s >> nod >> nok;
    add_arc(f, s, nok, nod);
  }
  for (int i = 1; i <= n; i++) {
    bool good = false;
    if (!value[i]) {
      for (int j = 1; j <= 1000000; j++) {
        memset(was, 0, sizeof was);
        value[i] = j;
        was[i] = true;
        if (DFS(i)) {
          good = true;
          break;
        }
      }
      if (!good) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES\n";
  for (int i = 1; i <= n; i++) {
    cout << value[i] << " ";
  }
  return 0;
}
