Pagini recente » Cod sursa (job #2777618) | Cod sursa (job #2210165) | Cod sursa (job #3148549) | Cod sursa (job #1456927) | Cod sursa (job #164800)
Cod sursa(job #164800)
program oz;
var a:array[1..100000] of integer;
f,g:text;ok:boolean;n,i,x,y,m,d:integer;
begin
assign(f,'oz.in');reset(f);
assign(g,'oz.out');rewrite(g);
readln(f,n,m);
for i:=1 to m do begin
readln(f,x,y,d);
if a[x]<>0 then a[x]:=a[x]*d
else a[x]:=d;
if a[y]<>0 then a[y]:=a[y]*d
else a[y]:=d;
end;
ok:=true;
for i:=1 to n do
if a[i]=0 then ok:=false;
if ok then for i:=1 to n do write(g,a[i],' ')
else writeln(g,'-1');
close(f);close(g);
end.