int dj()
{
priority_queue<PII, vector<PII>, greater<PII>> q;
memset(dist, 63, sizeof(dist));
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] > distance + w[i])
dist[j] = distance + w[i], q.push({dist[j], j});
}
}
res = INF;
for (int i = 0; i <= k; i++)
if (dist[ee[i].pos] < ee[i + 1].t)
return res = max(dist[ee[i].pos], ee[i].t);
return res;
}
这是一百分的代码,按照排序后每个节点的时间顺序来返回最小值,因为之前排好序了所以保证返回的res是最优值。
int dj()
{
priority_queue<PII, vector<PII>, greater<PII>> q;
memset(dist, 0x3f, sizeof(dist));
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] > distance + w[i])
dist[j] = distance + w[i], q.push({dist[j], j});
}
}
for (int i = 1; i <= n; i++)
if (dist[i] < p[i].ed)
dist[i] = max(dist[i], p[i].st);
else
dist[i] = INF;
res = INF;
for (int i = 1; i <= n; i++)
res = min(res, dist[i]);
return res;
}
这是五十分的代码,我是根据到达每个点的最短时间和当前点的结束时间进行比较,如果大于等于离开时间就设置为正无穷也就是从答案中排除,如果小于离开时间就要么我等他,要么他等我,取最大值,为什么这样做会少一半分数呢?