Pagini recente » Cod sursa (job #2165159) | Cod sursa (job #2983023) | Cod sursa (job #30823) | Cod sursa (job #399801) | Cod sursa (job #186905)
Cod sursa(job #186905)
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc(int a,int b){
if (b == 0) return a;
return cmmdc(b,a%b);
}
int A[10000];
int X[100000],Y[10000],Z[10000];
int N,M;
int main(void){
ifstream in("oz.in");
ofstream out("oz.out");
int a,b,c;
in >> N >> M;
for (int i=0;i<N;i++)
A[i] = 1;
for (int i=0;i<M;i++){
in >> a >> b >> c;
a--;
b--;
X[i] = a;
Y[i] = b;
Z[i] = c;
int k;
k = (A[a]*c)/cmmdc(A[a],c);
A[a] = k;
k = (A[b]*c)/cmmdc(A[b],c);
A[b] = k;
}
for (int i=0;i<M;i++)
if (cmmdc(A[X[i]],A[Y[i]]) != Z[i]){
out << -1;
in.close();
out.close();
return 0;
}
for (int i=0;i<N;i++){
out << A[i] << " ";
}
in.close();
out.close();
return 0;
}