Pagini recente » Cod sursa (job #2701775) | Cod sursa (job #1362030) | Cod sursa (job #2830164) | Cod sursa (job #3236305) | Cod sursa (job #169141)
Cod sursa(job #169141)
program oz;
var n,x,y: integer;
m,i,d: longint;
a: array[1..100000] of longint;
f: text;
t: 0..1;
function cmmdc(x,y: longint):longint;
begin
if y=0 then cmmdc:=x else
cmmdc:=cmmdc(y, x mod y);
end;
function at(k,h:longint):longint;
begin
if k=1 then at:=h else
if k mod h=0 then at:=k else
at:=k*h div cmmdc(k,h);
end;
begin
t:=1;
assign(f,'oz.in');
reset(f);
readln(f,n,m);
for i:=1 to n do
a[i]:=1;
for i:=1 to m do
begin
readln(f,x,y,d);
if d<>1 then begin
a[x]:=at(a[x],d);
a[y]:=at(a[y],d); end;
if cmmdc(a[x],a[y])=1 then
begin t:=0; break; end;
end;
close(f);
assign(f,'oz.out'); rewrite(f);
if t=0 then write(f,-1) else
for i:=1 to n do
write(f,a[i],' ');
close(f);
end.