{ tde } { Author's solution with topological sort } {$APPTYPE CONSOLE} {$B-,R-,O+} const maxn=500; maxk=3; inf=1000000000; type edge=record v:smallint; cost:longint; end; var fi,fo:text; n,m,k,i,j,t:longint; count:array[1..maxk] of longint; cost:array[1..maxk] of longint; num:array[1..maxn] of smallint; a:array[1..maxn,1..maxn] of edge; pay:array[1..maxn,1..maxk] of byte; towncost:array[1..maxn] of longint; aa,bb,cc:smallint; ans,start:longint; use,bestuse:array[1..maxk] of boolean; numtps:smallint; pos:array[1..maxn] of smallint; tps:array[1..maxn] of smallint; used:array[1..maxn] of boolean; f:array[1..maxn] of longint; procedure dfs(ver:smallint); var i:smallint; begin used[ver]:=true; for i:=1 to num[ver] do if(not used[a[ver,i].v])then dfs(a[ver,i].v); inc(numtps); tps[numtps]:=ver; pos[ver]:=numtps; end; begin assign(fi,'salesman.dat'); assign(fo,'salesman.sol'); reset(fi); rewrite(fo); readln(fi,n,m); k:=3; for i:=1 to k do read(fi,count[i]); readln(fi); for i:=1 to k do begin read(fi,cost[i]); cost[i]:=cost[i]*100; end; readln(fi); fillchar(pay,sizeof(pay),0); for i:=2 to n-1 do begin for j:=1 to k do read(fi,pay[i][j]); readln(fi); end; fillchar(num,sizeof(num),0); for i:=1 to m do begin readln(fi,aa,bb,cc); inc(num[bb]); a[bb,num[bb]].v:=aa; a[bb,num[bb]].cost:=cc*100; end; numtps:=0; fillchar(used,sizeof(used),0); for i:=1 to n do if(not used[i])then dfs(i); // topological sort ans:=0; for t:=0 to (1 shl k)-1 do begin for i:=1 to k do use[i]:=(t and (1 shl (i-1))<>0); start:=0; fillchar(towncost,sizeof(towncost),0); for i:=1 to k do if(use[i])then begin inc(start,count[i]*cost[i]); for j:=1 to n do inc(towncost[j],count[i]*cost[i] div 100*pay[j][i]); end; fillchar(f,sizeof(f),0); f[1]:=start; for i:=2 to n do for j:=1 to num[tps[i]] do if (f[tps[i]]ans)then begin ans:=f[n]; bestuse:=use; end; end; writeln(fo,(ans/100):0:2); {for i:=1 to k-1 do write(fo,integer(bestuse[i]),' '); writeln(fo,integer(bestuse[k]));} close(fi); close(fo); end.