Pagini recente » Cod sursa (job #2029368) | Cod sursa (job #2001637) | Cod sursa (job #2012800) | Cod sursa (job #1003006) | Cod sursa (job #2533940)
#include <bits/stdc++.h>
using namespace std;
#define NMAX 10005
#define MMAX 100005
typedef long long ll;
ll euclid(ll a, ll b) {
if(!b)
return a;
return euclid(b, a%b);
}
ll cmmmc(ll a, ll b) {
return a*b/euclid(a, b);
}
struct myType {
ll i, j, d;
};
vector<myType> date;
int main()
{
freopen("oz.in", "r", stdin);
freopen("oz.out", "w", stdout);
vector<ll> sir(NMAX, 1);
ll n, m;
scanf("%lld%lld", &n, &m);
for(ll k = 1; k <= m; ++k) {
myType temp;
scanf("%lld%lld%lld", &temp.i, &temp.j, &temp.d);
sir[temp.i] = cmmmc(sir[temp.i], temp.d);
sir[temp.j] = cmmmc(sir[temp.j], temp.d);
date.push_back(temp);
}
for(auto it = date.begin(); it != date.end(); ++it) {
if(euclid(sir[(*it).i], sir[(*it).j]) != (*it).d) {
printf("-1");
return 0;
}
}
for(ll i = 1; i <= n; ++i)
printf("%lld ", sir[i]);
return 0;
}