Cod sursa(job #290539)

Utilizator mariuscris90giuroiu marius mariuscris90 Data 28 martie 2009 02:16:47
Problema Oz Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.62 kb
program ozz;
type vect=array[1..10000] of longint;
var  t:boolean;
     v:vect;
     f,g:text;
     i,j,m,n,x,y,z:integer;
begin
assign(f,'oz.in');assign(g,'oz.out');reset(f);rewrite(g);
readln(f,n,m);t:=true;
for i:=1 to n do
v[i]:=1;
for i:=1 to m do begin
readln(f,x,y,z);
if v[x] mod z<>0 then if v[x]*z<=2000000000 then v[x]:=v[x]*z
                                            else t:=false;
if v[y] mod z<>0 then if v[y]*z<=2000000000 then v[y]:=v[y]*z
                                            else t:=false;
end;
if t then for i:=1 to n do write(g,v[i],' ')
     else write(g,-1);
close(f);close(g);end.