#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e9;
struct edge {
  int to;
  long long int gcd, lcm;
  edge() {}
  edge(int to, long long int gcd, long long int lcm)
      : to(to), gcd(gcd), lcm(lcm){};
};
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
long long int used[2000];
vector<edge> g[2000];
vector<int> path;
bool dfs(int id) {
  path.push_back(id);
  long long int mine = used[id];
  for (int i = 0; i < ((int)g[id].size()); i++) {
    int to = g[id][i].to;
    long long int gc = g[id][i].gcd;
    long long int lc = g[id][i].lcm;
    long long int q = lc * gc;
    if (q % mine) return false;
    long long int with = q / mine;
    if (gcd(with, mine) != gc || lcm(with, mine) != lc) return false;
    if (used[to] != -1) {
      if (with != used[to]) return false;
    } else {
      used[to] = with;
      if (!dfs(to)) return false;
    }
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--;
    b--;
    g[a].push_back(edge(b, c, d));
    g[b].push_back(edge(a, c, d));
  }
  memset(used, -1, sizeof used);
  for (int i = 0; i < (n); i++) {
    if (used[i] == -1) {
      path.clear();
      long long int hi = 1;
      for (int j = 0; j < ((int)(g[i]).size()); j++) {
        hi = lcm(hi, g[i][j].gcd);
      }
      bool yes = false;
      for (int j = 1; j < 10001; j++) {
        path.clear();
        used[i] = hi * j;
        if (dfs(i)) {
          yes = true;
          break;
        }
        for (int k = 0; k < ((int)(path).size()); k++) {
          used[path[k]] = -1;
        }
      }
      if (!yes) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < (n); i++) {
    printf("%I64d ", used[i]);
  }
}

### Prompt

Please create a solution in cpp to the following problem:

Pasha and Akim were making a forest map — the lawns were the graph's vertexes and the roads joining the lawns were its edges. They decided to encode the number of laughy mushrooms on every lawn in the following way: on every edge between two lawns they wrote two numbers, the greatest common divisor (GCD) and the least common multiple (LCM) of the number of mushrooms on these lawns. But one day Pasha and Akim had an argument about the laughy mushrooms and tore the map. Pasha was left with just some part of it, containing only m roads. Your task is to help Pasha — use the map he has to restore the number of mushrooms on every lawn. As the result is not necessarily unique, help Pasha to restore any one or report that such arrangement of mushrooms does not exist. It is guaranteed that the numbers on the roads on the initial map were no less that 1 and did not exceed 106.

Input

The first line contains two numbers n and m (<image>) which are the numbers of lawns and roads we know about. Each of the following m lines contains four numbers which are the numbers of lawns the road connects, the GCD and the LCM of the numbers of mushrooms on these lawns (1 ≤ GCD, LCM ≤ 106).

It is guaranteed, that no road connects lawn to itself, and no two lawns are connected by more than one road.

Output

The answer should contain "YES" or "NO" on the first line, saying whether it is possible or not to perform the arrangement. If the answer is "YES", print on the following line n numbers which are the numbers of mushrooms on the corresponding lawns.

Examples

Input

1 0


Output

YES
1 

Input

2 1
1 2 1 3


Output

YES
1 3 

Input

3 2
3 2 1 2
3 1 1 10


Output

YES
5 1 2 

Input

2 1
1 2 3 7


Output

NO

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e9;
struct edge {
  int to;
  long long int gcd, lcm;
  edge() {}
  edge(int to, long long int gcd, long long int lcm)
      : to(to), gcd(gcd), lcm(lcm){};
};
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
long long int used[2000];
vector<edge> g[2000];
vector<int> path;
bool dfs(int id) {
  path.push_back(id);
  long long int mine = used[id];
  for (int i = 0; i < ((int)g[id].size()); i++) {
    int to = g[id][i].to;
    long long int gc = g[id][i].gcd;
    long long int lc = g[id][i].lcm;
    long long int q = lc * gc;
    if (q % mine) return false;
    long long int with = q / mine;
    if (gcd(with, mine) != gc || lcm(with, mine) != lc) return false;
    if (used[to] != -1) {
      if (with != used[to]) return false;
    } else {
      used[to] = with;
      if (!dfs(to)) return false;
    }
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a--;
    b--;
    g[a].push_back(edge(b, c, d));
    g[b].push_back(edge(a, c, d));
  }
  memset(used, -1, sizeof used);
  for (int i = 0; i < (n); i++) {
    if (used[i] == -1) {
      path.clear();
      long long int hi = 1;
      for (int j = 0; j < ((int)(g[i]).size()); j++) {
        hi = lcm(hi, g[i][j].gcd);
      }
      bool yes = false;
      for (int j = 1; j < 10001; j++) {
        path.clear();
        used[i] = hi * j;
        if (dfs(i)) {
          yes = true;
          break;
        }
        for (int k = 0; k < ((int)(path).size()); k++) {
          used[path[k]] = -1;
        }
      }
      if (!yes) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < (n); i++) {
    printf("%I64d ", used[i]);
  }
}

```