#include <iostream>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
const int N = 1e3 + 5, M = 2e4 + 5;
int n, m, sx, ex, k, t0, a, b, c, h[N], e[M], ne[M], w[M], idx, dist[N], lim[M], p[N];
bool st[N];
struct node
{
int id, w;
};
map<pair<int, int>, node> ac;
typedef pair<int, int> PII;
void add(int a, int b, int c)
{
e[idx] = b, ne[idx] = h[a], w[idx] = c, ac[{a, b}] = {idx, c}, h[a] = idx++;
}
int dj()
{
memset(dist, 0x3f, sizeof(dist));
priority_queue<PII, vector<PII>, greater<PII>> q;
dist[sx] = 0, q.push({dist[sx], sx});
while (q.size())
{
PII t = q.top();
q.pop();
int ver = t.second;
if (st[ver])
continue;
st[ver] = true;
int distance = t.first;
for (int i = h[ver]; ~i; i = ne[i])
{
int j = e[i];
if (dist[j] > max(distance, lim[i]) + w[i])
dist[j] = max(distance, lim[i]) + w[i], q.push({dist[j], j});
}
}
return dist[ex];
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), memset(h, -1, sizeof(h));
cin >> n >> m >> sx >> ex >> t0 >> k, t0 = -t0;
for (int i = 1; i <= k; i++)
cin >> p[i];
while (m--)
cin >> a >> b >> c, add(a, b, c), add(b, a, c);
for (int i = 1; i < k; i++)
{
t0 += ac[{p[i], p[i + 1]}].w;
lim[ac[{p[i], p[i + 1]}].id] = lim[ac[{p[i + 1], p[i]}].id] = t0;
}
cout << dj() << endl;
}
思路和题解一样,都是求一个限制lim,限制的是边,并且也判断了路过相关的限制边要不要等待。样例第二个输出46,求指错