mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-20 19:26:37 +00:00
parent
840a925ada
commit
a3c732cf15
70
LibreOJ/2759/2759.cpp
Normal file
70
LibreOJ/2759/2759.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <queue>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
const int N = 100005;
|
||||||
|
|
||||||
|
int n, m, x, h[N], nh[N];
|
||||||
|
std::vector<std::pair<int, long long>> g[N];
|
||||||
|
|
||||||
|
// Dijkstra - Shortest Path
|
||||||
|
long long dist[N];
|
||||||
|
bool vis[N];
|
||||||
|
void dijkstra() {
|
||||||
|
memset(dist, 0x3f, sizeof(dist));
|
||||||
|
dist[1] = 0;
|
||||||
|
std::priority_queue<std::pair<long long, int>, std::vector<std::pair<long long, int>>, std::greater<std::pair<long long, int>>> q;
|
||||||
|
q.push(std::make_pair(0, 1));
|
||||||
|
nh[1] = x;
|
||||||
|
while (!q.empty()) {
|
||||||
|
int u = q.top().second;
|
||||||
|
q.pop();
|
||||||
|
if (vis[u]) continue;
|
||||||
|
vis[u] = true;
|
||||||
|
for (auto e : g[u]) {
|
||||||
|
int v = e.first;
|
||||||
|
long long w = e.second;
|
||||||
|
if (nh[u] - w > h[v]) { // 到达点的高度大于树顶高度
|
||||||
|
if (dist[v] > dist[u] + nh[u] - h[v]) {
|
||||||
|
dist[v] = dist[u] + nh[u] - h[v];
|
||||||
|
nh[v] = h[v];
|
||||||
|
q.push(std::make_pair(dist[v], v));
|
||||||
|
}
|
||||||
|
} else if (nh[u] - w < 0) { // 飞行中途会落地
|
||||||
|
if (dist[v] > dist[u] + w - nh[u] + w) {
|
||||||
|
dist[v] = dist[u] + w - nh[u] + w;
|
||||||
|
nh[v] = 0;
|
||||||
|
q.push(std::make_pair(dist[v], v));
|
||||||
|
}
|
||||||
|
} else if (dist[v] > dist[u] + w) { // 其他情况
|
||||||
|
dist[v] = dist[u] + w;
|
||||||
|
nh[v] = nh[u] - w;
|
||||||
|
q.push(std::make_pair(dist[v], v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin >> n >> m >> x;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> h[i];
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
int u, v;
|
||||||
|
long long w;
|
||||||
|
cin >> u >> v >> w;
|
||||||
|
|
||||||
|
// 保证飞行中途不落地
|
||||||
|
if (w <= h[u]) g[u].push_back(std::make_pair(v, w));
|
||||||
|
if (w <= h[v]) g[v].push_back(std::make_pair(u, w));
|
||||||
|
}
|
||||||
|
dijkstra();
|
||||||
|
cout << (dist[n] == 0x3f3f3f3f3f3f3f3f ? -1 : dist[n] + h[n] - nh[n]) << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
LibreOJ/2759/data/1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/10.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/11.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/11.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/12.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/12.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/13.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/13.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/14.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/14.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/15.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/15.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/16.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/16.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/17.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/17.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/18.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/18.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/19.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/19.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/20.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/20.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/21.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/21.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/21.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/21.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/22.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/22.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/22.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/22.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/23.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/23.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/23.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/23.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/24.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/24.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/24.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/24.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/25.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/25.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/25.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/25.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/26.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/26.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/26.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/26.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/27.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/27.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/27.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/27.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/28.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/28.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/28.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/28.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/29.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/29.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/29.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/29.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/30.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/30.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/30.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/30.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/31.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/31.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/31.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/31.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/32.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/32.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/32.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/32.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/33.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/33.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/33.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/33.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/34.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/34.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/34.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/34.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/35.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/35.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/35.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/35.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/36.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/36.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/36.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/36.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/37.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/37.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/37.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/37.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/38.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/38.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/38.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/38.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/39.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/39.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/39.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/39.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/40.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/40.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/40.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/40.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/41.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/41.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/41.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/41.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/42.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/42.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/42.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/42.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/43.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/43.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/43.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/43.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/44.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/44.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/44.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/44.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/45.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/45.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/45.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/45.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/46.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/46.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/46.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/46.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/47.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/47.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/47.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/47.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/48.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/48.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/48.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/48.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/49.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/49.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/49.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/49.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/50.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/50.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/50.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/50.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/51.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/51.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/51.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/51.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/52.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/52.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/52.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/52.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/53.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/53.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/53.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/53.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2759/data/54.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2759/data/54.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user