#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2020;
int dp[N][N/2],st[N][N/2],op[N];
struct Node
{
int me,d,c;//c表示系数,d表示总花费时间,me表示处于某点
bool operator<(struct Node x)const
{
return d>x.d;
}
};
typedef struct Node node;
int e[N],ne[N],h[N],w[N],idx;
void add(int a, int b, int c) // 添加一条边a->b,边权为c
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}
void dij()
{
priority_queue<node,vector<node>> q;
q.push({1,0,op[1]});
dp[1][op[1]]=0;
while(q.size()){
auto t=q.top();
q.pop();
int x=t.me,y=t.c;
if(st[x][y])continue;
st[x][y]=true;
for(int i=h[x];~i;i=ne[i]){
int j=e[i],d=w[i];
int c=min(y,op[j]);
if(dp[j][c]>dp[x][y]+d*y){
dp[j][c]=dp[x][y]+d*y;
q.push({j,dp[j][c],c});
}
}
}
}
void solve()
{
int n,m;
cin>>n>>m;
idx=0;
for(int i=1;i<=n;i++){
h[i]=-1;
for(int j=0;j<1001;j++)st[i][j]=false,dp[i][j]=1e17;
}
for(int i=1;i<=m;i++){
int a,b,c;
cin>>a>>b>>c;
add(a,b,c),add(b,a,c);
}
for(int i=1;i<=n;i++)cin>>op[i];
dij();
int ans=1e17;
for(int i=1;i<=1000;i++)ans=min(ans,dp[n][i]);
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin>>T;
while(T--)solve();
return 0;
}
Codeforces Round 918 (Div. 4) G
最新推荐文章于 2024-08-09 22:34:59 发布