※NC14700 追债之旅
最短路变形题,加一维状态就好啦
\(dist[i][j]\)表示到达第\(i\)号点,到达时间为第\(j\)天的最短距离
- 判重数组要和\(dist\)数组一致
直接跑\(dijkstra\)即可
const int N=1010;
vector<PII> g[N];
struct Node
{
int dis,u,day;
bool operator>(const Node &W) const
{
return dis>W.dis;
}
};
int dist[N][15];
bool vis[N][15];
int cost[15];
int n,m,k;
void dijkstra()
{
memset(dist,0x3f,sizeof dist);
priority_queue<Node,vector<Node>,greater<Node> > heap;
dist[1][0]=0;
heap.push({0,1,0});
while(heap.size())
{
int t=heap.top().u,d=heap.top().day;
heap.pop();
if(vis[t][d]) continue;
vis[t][d]=true;
for(int i=0;i<g[t].size();i++)
{
int j=g[t][i].fi,w=g[t][i].se;
if(d+1<=k && dist[j][d+1] > dist[t][d] + w + cost[d+1])
{
dist[j][d+1]=dist[t][d]+w+cost[d+1];
heap.push({dist[j][d+1],j,d+1});
}
}
}
}
int main()
{
cin>>n>>m>>k;
while(m--)
{
int a,b,c;
cin>>a>>b>>c;
g[a].pb({b,c});
g[b].pb({a,c});
}
for(int i=1;i<=k;i++) cin>>cost[i];
dijkstra();
int res=INF;
for(int i=1;i<=k;i++)
res=min(res,dist[n][i]);
if(res == INF) puts("-1");
else cout<<res<<endl;
//system("pause");
}