期望DP
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
using namespace std;
inline int rd(){
int ret=0,f=1;char c;
while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
while(isdigit(c))ret=ret*10+c-'0',c=getchar();
return ret*f;
}
const int MAXN = 2048;
int t1[MAXN],t2[MAXN];
double p[MAXN],f[MAXN][MAXN][2],mp[305][305];
int n,m,v,e;
void init(){
memset(f,127,sizeof(f));
memset(mp,127,sizeof(mp));
}
int main(){
init();
n=rd();m=rd();v=rd();e=rd();
for(int i=1;i<=n;i++)t1[i]=rd();
for(int i=1;i<=n;i++)t2[i]=rd();
for(int i=1;i<=n;i++)scanf("%lf",&p[i]);
int x,y;double w;
for(int i=1;i<=e;i++){
x=rd();y=rd();scanf("%lf",&w);
mp[x][y]=mp[y][x]=min(w,mp[x][y]);
}
for(int i=1;i<=v;i++)mp[i][i]=0;//??!!
for(int k=1;k<=v;k++){
for(int i=1;i<=v;i++){
for(int j=1;j<=v;j++){
mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
}
}
}
f[1][0][0]=f[1][1][1]=0;
for(int i=2;i<=n;i++){
for(int j=0;j<=m;j++){
//1
f[i][j][0]=min(f[i][j][0],min(
f[i-1][j][0]+mp[t1[i-1]][t1[i]],//上一个不换
f[i-1][j][1]+p[i-1]*mp[t2[i-1]][t1[i]]+(1.0-p[i-1])*mp[t1[i-1]][t1[i]]));//上一个换
//2
if(j==0)continue;
f[i][j][1]=min(f[i][j][1],min(//当前换
f[i-1][j-1][0]+p[i]*mp[t1[i-1]][t2[i]]+(1.0-p[i])*mp[t1[i-1]][t1[i]],//上一个不换
f[i-1][j-1][1]+p[i-1]*p[i]*mp[t2[i-1]][t2[i]]
+p[i-1]*(1.0-p[i])*mp[t2[i-1]][t1[i]]
+(1.0-p[i-1])*p[i]*mp[t1[i-1]][t2[i]]
+(1.0-p[i-1])*(1.0-p[i])*mp[t1[i-1]][t1[i]]));
}
}
double ans=1e9;
for(int j=0;j<=m;j++){
ans=min(ans,min(f[n][j][0],f[n][j][1]));
}
printf("%.2lf",ans);
return 0;
}