Pagini recente » Cod sursa (job #1489431) | Cod sursa (job #2259740) | Cod sursa (job #303516) | Cod sursa (job #2837574) | Cod sursa (job #163539)
Cod sursa(job #163539)
var a,b,i,j,n,m,c,c1,c2:longint;
v:array[1..11000] of int64;
ok:boolean;
function cmmdc(a,b:longint):longint;
var r:longint;
begin
r:=a mod b;
while r>0 do
begin
a:=b;
b:=r;
r:=a mod b;
end;
cmmdc:=b;
end;
begin
assign(input,'oz.in');reset(input);
assign(output,'oz.out');rewrite(output);
readln(n,m);
for i:=1 to n do
v[i]:=1;
for i:=1 to m do
begin
readln(a,b,c);
c1:=cmmdc(v[a],c);
c2:=cmmdc(v[b],c);
v[a]:=(v[a]*c) div c1;
if a<>b then
v[b]:=(v[b]*c) div c2;
end;
close(input);
reset(input);
readln(n,m);
ok:=true;
for i:=1 to m do
begin
readln(a,b,c);
c1:=cmmdc(v[a],v[b]);
if c1<>c then
begin
ok:=false;
break;
end;
// writeln(a,' ',b);
end;
if not ok then
write('-1')
else
for i:=1 to n do
write(v[i],' ');
writeln;
close(input);close(output);
end.