#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <unordered_map>
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;
const ll INF = 987654321987654321;
const int MX = 2625;
struct Edge {
int src, dst, w;
bool operator<(const Edge &p) const {
return w > p.w;
}
};
int fuel[MX];
unordered_map<int, ll> cost[MX];
vector <Edge> G[MX];
void dijkstra(int start, vector<Edge> graph[])
{
cost[start][fuel[start]] = 0;
priority_queue<Edge> pq;
pq.push({0, start,0});
while(!pq.empty()) {
Edge x = pq.top();
pq.pop();
for (auto ed : graph[x.dst]) {
bool flag = false;
for (auto p : cost[ed.src]) {
int j = p.first;
int fcost = min(fuel[ed.dst], j);
int v = ed.dst;
int w = ed.w * j;
if ((cost[v].find(fcost) == cost[v].end()) or (cost[v][fcost] > p.second + w)) {
flag = true;
cost[v][fcost] = p.second + w;
}
}
if (flag) pq.push(ed);
}
}
}
int32_t main() {
usecppio
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> fuel[i];
for (int i = 0; i < m; i++) {
int u, v, w; cin >> u >> v >> w;
G[u].push_back({u, v, w});
G[v].push_back({v, u, w});
}
dijkstra(1, G);
ll ans = INF;
for (auto p : cost[n]) ans = min(ans, p.second);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
844 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
2 ms |
972 KB |
Output is correct |
6 |
Correct |
2 ms |
844 KB |
Output is correct |
7 |
Correct |
2 ms |
972 KB |
Output is correct |
8 |
Correct |
2 ms |
844 KB |
Output is correct |
9 |
Correct |
3 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
844 KB |
Output is correct |
2 |
Correct |
8 ms |
972 KB |
Output is correct |
3 |
Correct |
8 ms |
1068 KB |
Output is correct |
4 |
Correct |
6 ms |
972 KB |
Output is correct |
5 |
Correct |
6 ms |
972 KB |
Output is correct |
6 |
Correct |
4 ms |
972 KB |
Output is correct |
7 |
Correct |
5 ms |
972 KB |
Output is correct |
8 |
Correct |
5 ms |
1056 KB |
Output is correct |
9 |
Correct |
5 ms |
972 KB |
Output is correct |
10 |
Correct |
3 ms |
972 KB |
Output is correct |
11 |
Correct |
3 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Execution timed out |
2095 ms |
4244 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
844 KB |
Output is correct |
15 |
Correct |
2 ms |
972 KB |
Output is correct |
16 |
Correct |
2 ms |
972 KB |
Output is correct |
17 |
Correct |
2 ms |
972 KB |
Output is correct |
18 |
Correct |
2 ms |
972 KB |
Output is correct |
19 |
Correct |
2 ms |
844 KB |
Output is correct |
20 |
Correct |
2 ms |
972 KB |
Output is correct |
21 |
Correct |
2 ms |
844 KB |
Output is correct |
22 |
Correct |
3 ms |
844 KB |
Output is correct |
23 |
Correct |
2 ms |
844 KB |
Output is correct |
24 |
Correct |
2 ms |
844 KB |
Output is correct |
25 |
Correct |
8 ms |
972 KB |
Output is correct |
26 |
Correct |
8 ms |
1068 KB |
Output is correct |
27 |
Correct |
6 ms |
972 KB |
Output is correct |
28 |
Correct |
6 ms |
972 KB |
Output is correct |
29 |
Correct |
4 ms |
972 KB |
Output is correct |
30 |
Correct |
5 ms |
972 KB |
Output is correct |
31 |
Correct |
5 ms |
1056 KB |
Output is correct |
32 |
Correct |
5 ms |
972 KB |
Output is correct |
33 |
Correct |
3 ms |
972 KB |
Output is correct |
34 |
Correct |
3 ms |
972 KB |
Output is correct |
35 |
Correct |
1 ms |
588 KB |
Output is correct |
36 |
Correct |
1 ms |
588 KB |
Output is correct |
37 |
Correct |
1 ms |
588 KB |
Output is correct |
38 |
Execution timed out |
2095 ms |
4244 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |