Pagini recente » Cod sursa (job #2952099) | Cod sursa (job #500027) | Cod sursa (job #906015) | Cod sursa (job #693121) | Cod sursa (job #3186394)
#include <bits/stdc++.h>
using namespace std;
#define MMAX 100001
#define NMAX 10001
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;
}
int 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;
exit(1);
}
}
for(int i= 1;i<=n;i++){
cout << a[i] << ' ';
}
}