Pagini recente » Cod sursa (job #2089681) | Cod sursa (job #967203) | Cod sursa (job #2543034) | Cod sursa (job #2971789) | Cod sursa (job #584358)
Cod sursa(job #584358)
var b:array[0..15,1..2000] of longint;
o:array[0..17] of longint;
n,m,k,i,j,a,s,c:longint;
L:int64;
bo:boolean;
f,g:text;
procedure verificare;
var i:longint; x:int64;
begin
x:=0;
for i:=1 to k+1 do
x:=x+b[o[i],o[i+1]];
if x<L then L:=x;
end;
procedure sw(var a,b:longint);
var t:longint;
begin
t:=a; a:=b; b:=t;
end;
procedure perm(p:longint);
var i:longint;
begin
if p>k then verificare else
begin
for i:=p to k do
begin
sw(o[i+1],o[p+1]);
perm(p+1);
sw(o[i],o[p+1]);
end;
end;
end;
begin
assign(f,'ubuntzei.in');
assign(g,'ubuntzei.out');
reset(f);
rewrite(g);
readln(f,n,m);
read(f,k);
o[1]:=1;
o[k+2]:=n;
for i:=2 to k+1 do
read(f,o[i]);
for i:=1 to k+1 do
for j:=1 to n do
b[i,j]:=-1;
for i:=1 to k+1 do
begin
b[i,o[i]]:=0;
bo:=true;
while bo do
begin
reset(f);
readln(f);
readln(f);
bo:=false;
for j:=1 to m do
begin
readln(f,a,s,c);
if ((b[i,a]>-1)and((b[i,s]=-1)or(b[i,s]>b[i,a]+c))) then
begin
b[i,s]:=b[i,a]+c;
bo:=true;
end;
if ((b[i,s]>-1)and((b[i,a]=-1)or(b[i,a]>b[i,s]+c))) then
begin
b[i,a]:=b[i,s]+c;
bo:=true;
end;
end;
end;
end;
L:=2000000000;
perm(1);
writeln(g,L);
close(g);
end.