#include <bits/stdc++.h>
using namespace std;
int adj[101][101];
int dp[101][101][258];
bool hascal[101][101][258];
int s[8],ss;
int solve(int x,int y, int mask)
{
if(hascal[x][y][mask])
{
return dp[x][y][mask];
}
if(mask==0)
{
return 0; ///Return 0 if we're done since there's nothing else to do
}
else
{
hascal[x][y][mask]=true;
int temp;
int mn=INT_MAX;
for(temp=0;temp<ss;temp++)
{
if(mask & (1<<temp))
{
int target=s[temp];
mn=min(mn,solve(target,y,mask ^ (1<<temp))+adj[x][target]); ///The addition is outside of the solve function
mn=min(mn,solve(x,target,mask ^ (1<<temp))+adj[y][target]); ///Since we move to that state at such cost
}
}
dp[x][y][mask]=mn;
return mn;
}
}
int main()
{
int temp,temp2,temp3,INF=10e8;
for(temp=0;temp<=100;temp++)
{
for(temp2=0;temp2<=100;temp2++)
{
if(temp==temp2)
adj[temp][temp2]=0;
else
adj[temp][temp2]=INF;
}
}
int m,n;
scanf("%d %d",&m,&n);
for(temp=0;temp<n;temp++)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
adj[a][b]=adj[b][a]=min(adj[a][b],c);
}
for(temp3=0;temp3<m;temp3++)
{
for(temp=0;temp<m;temp++)
{
for(temp2=0;temp2<m;temp2++)
{
adj[temp2][temp]=min(adj[temp][temp2],adj[temp][temp3]+adj[temp3][temp2]);
}
}
}
scanf("%d",&ss);
for(temp=0;temp<ss;temp++)
{
scanf("%d",&s[temp]);
}
int x,y;
scanf("%d %d",&x,&y);
int ans=solve(x,y,pow(2,ss)-1);
printf("%d\n",ans);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgYWRqWzEwMV1bMTAxXTsKaW50IGRwWzEwMV1bMTAxXVsyNThdOwpib29sIGhhc2NhbFsxMDFdWzEwMV1bMjU4XTsKaW50IHNbOF0sc3M7CgppbnQgc29sdmUoaW50IHgsaW50IHksIGludCBtYXNrKQp7CglpZihoYXNjYWxbeF1beV1bbWF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