#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof a)
#define N 1009
#define M 20009
int h[N];
int e[M],ne[M],idx,a[20],w[M];
ll dist[20][N];
int vis[20][N];
int n,m,k;
struct node
{
ll day,p,val;
bool operator < (const node &t) const
{
return val>t.val;
}
};
ll Read()
{
char ch;
ll s=0,w=1;
ch = getchar();
while(ch<'0'||ch>'9'){if(ch=='-') w = -1; ch = getchar();}
while(ch>='0'&&ch<='9'){ s = s*10 +ch-'0'; ch = getchar(); }
return s*w;
}
void add(int x,int y,int z)
{
e[idx] = y;
w[idx] = z;
ne[idx] = h[x];
h[x] = idx++;
}
void Dijstra()
{
mem(dist,INF);
dist[0][1]=0;
priority_queue<node> heap;
heap.push({0,1,0});
while(heap.size())
{
node tmp = heap.top();
heap.pop();
int day = tmp.day,p = tmp.p,val= tmp.val;
if(vis[day][p]) continue;
vis[day][p] = 1;
for(int i=h[p]; i!=-1; i=ne[i])
{
if(day+1>k) continue;
int j = e[i];
if(dist[day+1][j]>val+a[day+1]+w[i])
{
dist[day+1][j] = a[day+1]+val+w[i];
heap.push({day+1,j,dist[day+1][j]});
}
}
}
}
int main() {
mem(h,-1);
cin>>n>>m>>k;
for(int i=0; i<m; i++)
{
int x,y,z;
cin>>x>>y>>z;
add(x,y,z);
add(y,x,z);
}
for(int i=1; i<=k; i++)
{
cin>>a[i];
}
Dijstra();
ll ans = INF;
for(int i=1; i<=k; i++)
ans = min(ans,dist[i][n]);
if(ans==INF) printf("-1");
else cout<<ans<<endl;
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话