#include <bits/stdc++.h>
using namespace std;
int adjgcd[100][100];
int adjlcm[100][100];
int nComp;
int comp[100];
int vis[100];
int nLawns;
int nRoads;
long long gcdfun(long long a, long long b) {
  long long c = a;
  while (b != 0) {
    long long t = c % b;
    c = b;
    b = t;
  }
  return c;
}
long long lcmfun(long long a, long long b) { return a * (b / gcdfun(a, b)); }
void dfsComp(int node, int compNum) {
  if (comp[node] == -1) {
    comp[node] = compNum;
    for (int neighbor = 0; neighbor < (nLawns); ++neighbor) {
      if (adjgcd[node][neighbor] > 0) {
        dfsComp(neighbor, compNum);
      }
    }
  } else {
    assert(comp[node] == compNum);
  }
}
bool check(long long a, long long b, long long gcd, long long lcm) {
  return gcdfun(a, b) == gcd && lcmfun(a, b) == lcm;
}
bool dfsTest(int node, int value) {
  vis[node] = value;
  for (int neighbor = 0; neighbor < (nLawns); ++neighbor) {
    if (adjgcd[node][neighbor] > 0) {
      long long gcd = (long long)adjgcd[node][neighbor];
      long long lcm = (long long)adjlcm[node][neighbor];
      long long a = (long long)vis[node];
      if (vis[neighbor] == -1) {
        if (!check(a, gcd * lcm / a, gcd, lcm) ||
            !dfsTest(neighbor, gcd * lcm / a)) {
          return false;
        }
      } else {
        if (!check(a, vis[neighbor], gcd, lcm)) {
          return false;
        }
      }
    }
  }
  return true;
}
bool test(int node) {
  for (int a = 1; a * a <= 1000000; ++a) {
    int d = 1000000 / a;
    for (int i = 0; i < (nLawns); ++i) {
      if (comp[i] == comp[node]) vis[i] = -1;
    }
    if (dfsTest(node, a)) return true;
    if (a * d == 1000000 && dfsTest(node, d)) return true;
  }
  return false;
}
int main() {
  cin >> nLawns >> nRoads;
  for (int i = 0; i < (nRoads); ++i) {
    int from, to, gcd, lcm;
    cin >> from >> to >> gcd >> lcm;
    --from;
    --to;
    adjgcd[from][to] = adjgcd[to][from] = gcd;
    adjlcm[from][to] = adjlcm[to][from] = lcm;
  }
  memset(comp, -1, sizeof(comp));
  nComp = 0;
  for (int i = 0; i < (nLawns); ++i) {
    if (comp[i] == -1) {
      dfsComp(i, nComp++);
    }
  }
  memset(vis, -1, sizeof(vis));
  for (int i = 0; i < (nLawns); ++i) {
    if (vis[i] == -1) {
      if (!test(i)) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < (nLawns); ++i) {
    if (i > 0) cout << " ";
    cout << vis[i];
  }
  cout << endl;
  return 0;
}
