Pagini recente » Cod sursa (job #3910) | Cod sursa (job #3272365) | Cod sursa (job #1495942) | Cod sursa (job #3187981) | Cod sursa (job #186911)
Cod sursa(job #186911)
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;
LL cmmdc(int a,int b){
if (b == 0) return a;
return cmmdc(b,a%b);
}
LL A[10000];
LL X[100000],Y[100000],Z[100000];
LL N,M;
int main(void){
ifstream in("oz.in");
ofstream out("oz.out");
LL 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;
LL 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;
}