Pagini recente » Cod sursa (job #2024839) | Cod sursa (job #94653) | Cod sursa (job #2310633) | Cod sursa (job #395611) | Cod sursa (job #3241427)
#include <bits/stdc++.h>
using namespace std;
#define MMAX 100001
#define NMAX 10001
#define int long long
pair<int,pair<int,int>> t[MMAX];
int a[NMAX];
void init(){
for(int i = 1;i<=NMAX-1;i++){
a[i] = 1;
}
}
int cmmmc(int a, int b){
return a / __gcd(a,b) * b;
}
signed main(void){
ofstream cout("oz.out");
ifstream cin("oz.in");
init();
int n,m,x;
cin >> n >> m;
for(int i = 1;i<=m;i++){
cin >> t[i].first >> t[i].second.first >> x;
a[t[i].first] = cmmmc(a[t[i].first], x);
a[t[i].second.first] = cmmmc(a[t[i].second.first], x);
t[i].second.second = x;
}
for(int i = 1;i<=m;i++){
if(__gcd(a[t[i].first], a[t[i].second.first]) != t[i].second.second){
cout << -1;
return 0;
}
}
for(int i= 1;i<=n;i++){
cout << a[i] << ' ';
}
}