program gpaths;
var n:array [1..1000,1..2] of integer;
    k:array [2..10000] of integer;
    i:array [1..1000] of integer;
    j:array [1..1000] of integer;
    c:array [1..1000] of integer;
    s:array [1..1000] of integer;
    a,b,z,y,x:integer;
begin
write('vavedete broq na krastovi6tata ');readln(a);
write('vavedete broq na zalite ');readln(b);
for z:=1 to (a-1) do
begin
write('i= ');read(i[z]);
write('j= ');read(j[z]);
write('c= ');read(c[z]);
end;
for y:=1 to b do
begin
write('k= ');read(k[y]);
end;
for z:=1 to a do
s[1]:=c[1];
begin
if (j[z]=i[z+1]) or (j[z]=j[z+1]) or (i[z]=j[z+1]) then
s[z]:=s[z]+c[z+1];
readln(s[z]);
end;
end.