#include <bits/stdc++.h>
using namespace std;
int arr[101][101][2], use[101][2], n, m, f = 1;
int GCD(int a, int b) {
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int dfs(int a) {
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (arr[a][i][0] && !use[i][0]) {
      if (((long long)arr[a][i][0] * arr[a][i][1]) % (use[a][1]) == 0) {
        use[i][1] = ((long long)arr[a][i][0] * arr[a][i][1]) / (use[a][1]);
        use[i][0] = 1;
        for (int j = 1; j <= n; j++)
          if (arr[i][j][0] && use[j][0])
            if (GCD(use[i][1], use[j][1]) != arr[i][j][0] ||
                ((long long)use[i][1] * use[j][1] / arr[i][j][0]) !=
                    (long long)arr[i][j][1])
              return 1;
        ans += dfs(i);
      } else
        return 1;
    }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int f1, f2, nod, nok;
    cin >> f1 >> f2 >> nod >> nok;
    arr[f1][f2][0] = arr[f2][f1][0] = nod;
    arr[f1][f2][1] = arr[f2][f1][1] = nok;
  }
  for (int i = 1; i <= n; i++)
    while (use[i][0] != 2 && f) {
      int to = 0;
      for (int v = 1; v <= n; v++)
        if (arr[i][v][0]) to = v;
      if (to && arr[i][to][1] % arr[i][to][0] == 0) {
        int val = arr[i][to][1] / arr[i][to][0], sq, cnt, s;
        sq = sqrt((double)val);
        map<int, int> mp;
        vector<pair<int, int> > lst;
        for (int i = 2; i <= sq; i++)
          while (val % i == 0) {
            mp[i]++;
            val /= i;
          }
        mp[val]++;
        for (map<int, int>::iterator p = mp.begin(); p != mp.end(); p++)
          lst.push_back(*p);
        cnt = 1 << (lst.size());
        s = lst.size();
        f = 0;
        for (int j = 0; j < cnt; j++) {
          int val = arr[i][to][0];
          for (int k = 0; k < s; k++)
            if (j & (1 << k)) val *= pow((double)lst[k].first, lst[k].second);
          use[i][0] = 1;
          use[i][1] = val;
          if (!dfs(i)) {
            f = 1;
            for (int l = 1; l <= n; l++)
              if (use[l][0] == 1) use[l][0] = 2;
            break;
          } else
            for (int l = 1; l <= n; l++)
              if (use[l][0] == 1) use[l][0] = 0;
        }
      } else if (!to) {
        use[i][0] = 2;
        use[i][1] = 1;
      } else
        f = 0;
    }
  if (f) {
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++) cout << use[i][1] << " ";
  } else
    cout << "NO";
  return 0;
}
