#include <bits/stdc++.h>
using namespace std;
long long n, m;
inline long long gcd(long long a, long long b) {
  while (a && b)
    if (a > b)
      a %= b;
    else
      b %= a;
  return max(a, b);
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long num[101];
vector<long long> ver[101], g[101], l[101];
bool arr[101];
inline void addedge(long long a, long long b, long long c, long long d) {
  ver[a].push_back(b);
  g[a].push_back(c);
  l[a].push_back(d);
  ver[b].push_back(a);
  g[b].push_back(c);
  l[b].push_back(d);
}
inline bool bfs(long long start, long long startnum) {
  queue<long long> q;
  bool inq[101];
  memset(inq, 0, sizeof(inq));
  bool vis[101];
  memset(vis, 0, sizeof(vis));
  q.push(start);
  num[start] = startnum;
  vis[start] = 1;
  while (q.size()) {
    long long old = q.front();
    q.pop();
    inq[old] = 0;
    for (long long i = 0; i < (long long)ver[old].size(); i++) {
      long long y = ver[old][i], nxtnum = l[old][i] / num[old] * g[old][i];
      if (g[old][i] * l[old][i] % num[old] ||
          gcd(num[old], nxtnum) != g[old][i] ||
          lcm(num[old], nxtnum) != l[old][i])
        return 0;
      if (vis[y]) {
        if (num[y] != nxtnum) return 0;
        continue;
      }
      vis[y] = 1;
      num[y] = nxtnum;
      q.push(y);
    }
  }
  for (long long i = 1; i <= n; i++)
    if (vis[i]) arr[i] = 1;
  return 1;
}
inline void deal(long long x) {
  if (ver[x].size() == 0) {
    arr[x] = 1;
    num[x] = 1;
    return;
  }
  for (long long i = g[x][0]; i <= l[x][0]; i += g[x][0])
    if (bfs(x, i)) return;
  puts("NO");
  exit(0);
}
inline void init() {
  cin >> n >> m;
  while (m--) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    addedge(a, b, c, d);
  }
}
signed main() {
  init();
  for (long long i = 1; i <= n; i++)
    if (!arr[i]) deal(i);
  puts("YES");
  for (long long i = 1; i <= n; i++) cout << num[i] << ' ';
}
