#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
const int MAXM = 5001;
const int MAXVAL = 1000000;
vector<int> gra[MAXN], vf;
int edge[MAXM][4];
int ans[MAXN];
int GCD(int a, int b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int GetAnotherNum(int num, int gcd, int lcm) {
  long long ret;
  if ((long long)gcd * lcm % num != 0)
    ret = -1;
  else {
    ret = (long long)gcd * lcm / num;
    if (GCD(ret, num) != gcd || ret * num / GCD(ret, num) != lcm ||
        ret > MAXVAL)
      ret = -1;
  }
  return (int)ret;
}
bool DFS(int k) {
  vf.push_back(k);
  for (vector<int>::iterator iter = gra[k].begin(); iter != gra[k].end();
       iter++) {
    int ei = *iter;
    int otherval = GetAnotherNum(ans[k], edge[ei][2], edge[ei][3]);
    int otherindex;
    if (edge[ei][0] == k)
      otherindex = edge[ei][1];
    else
      otherindex = edge[ei][0];
    if (otherval < 0) return false;
    if (ans[otherindex] == 0) {
      ans[otherindex] = otherval;
      if (!DFS(otherindex)) return false;
    } else if (ans[otherindex] != otherval)
      return false;
  }
  return true;
}
bool Work(int n) {
  for (int i = 1; i <= n; i++)
    if (ans[i] == 0) {
      if (gra[i].empty())
        ans[i] = 1;
      else {
        bool okay = false;
        int ei = gra[i].front();
        int a = edge[ei][3] / edge[ei][2];
        for (int j = 1; j <= (int)sqrt(a); j++)
          if (a % j == 0 && GCD(j, a / j) == 1) {
            vf.clear();
            ans[i] = j * edge[ei][2];
            if (DFS(i)) {
              okay = true;
              break;
            }
            for (vector<int>::iterator iter = vf.begin(); iter != vf.end();
                 iter++)
              ans[*iter] = 0;
            vf.clear();
            ans[i] = (a / j) * edge[ei][2];
            if (DFS(i)) {
              okay = true;
              break;
            }
            for (vector<int>::iterator iter = vf.begin(); iter != vf.end();
                 iter++)
              ans[*iter] = 0;
          }
        if (!okay) return false;
      }
    }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> edge[i][0] >> edge[i][1] >> edge[i][2] >> edge[i][3];
    gra[edge[i][0]].push_back(i);
    gra[edge[i][1]].push_back(i);
  }
  if (Work(n)) {
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  } else
    cout << "NO" << endl;
  return 0;
}
