Pagini recente » Cod sursa (job #2034183) | Istoria paginii utilizator/tudorsavu | Rating Zozo Zozo (Zozel) | Cod sursa (job #659843) | Cod sursa (job #1388043)
#include <fstream>
#define DIM 10010
using namespace std;
ifstream fin ("oz.in" );
ofstream fout("oz.out");
int N, M, i, j, K, x, y, z;
int Q, V[DIM], ok;
short W[DIM*10][4];
void SetUp(){
fin >> N >> Q;
for(i = 1; i <= N; i ++)
V[i] = 1;
return;
}
int cmmdc(int a, int b){
while(b != 0){
int c = a % b;
a = b; b = c;
}
return a;
}
void CodeExpert(){
ok = 1;
for(i = 1; i <= Q; i ++){
fin >> x >> y >> z;
W[i][1] = x;
W[i][2] = y;
W[i][3] = z;
V[x] = (V[x] * z) / (cmmdc(V[x], z));
V[y] = (V[y] * z) / (cmmdc(V[y], z));
}
return;
}
void Verify(){
for(i = 1; i <= Q; i ++){
x = W[i][1];
y = W[i][2];
z = W[i][3];
if(cmmdc(V[x], V[y]) != z){
ok = 0; break;
}
}
return;
}
void Finish(){
if(ok == 0){
fout << -1;
return;
}
for(i = 1; i <= N; i ++)
fout << V[i] << " ";
return;
}
int main(){
SetUp();
CodeExpert();
Verify();
Finish();
return 0;
}