Pagini recente » Rating Popescu Ioan (giotoziloiu) | Cod sursa (job #3172991)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("oz.in");
ofstream out("oz.out");
int n,m;
vector<pair<pair<int,int>, int>> t;
// pair<int, int> (i,j) si int (d)
int main()
{
in.tie(0);
ios_base::sync_with_stdio(0);
in >> n >> m;
vector<ll> v(n, 1);
t.resize(m);
for (int i=0; i<m; ++i) {
int x, y, d;
in >> x >> y >> d;
x--; y--;
t[i] = {{x, y}, d};
v[x] = v[x] * d / gcd(v[x], d);
v[y] = v[y] * d / gcd(v[y], d);
}
for (auto& it : t) {
int x = it.first.first;
int y = it.first.second;
int d = it.second;
if (gcd(v[x], v[y]) != d) {
out << -1;
return 0;
}
}
for(const auto& it : v)
out << it << " ";
return 0;
}