This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<array<int, 4>> adj[200005];
ll dist[200005];
long long solve(int n, int m, int w, std::vector<int> T, std::vector<int> X, std::vector<int> Y,
std::vector<int> A, std::vector<int> B, std::vector<int> C, std::vector<int> L,
std::vector<int> R)
{
for (int i = 0; i < n; i++)
adj[i].clear();
for (int i = 0; i < m; i++)
adj[X[i]].push_back({A[i], B[i], Y[i], C[i]});
for (int i = 0; i < n; i++)
sort(adj[i].begin(), adj[i].end());
dist[0] = 0;
for (int i = 1; i < n; i++)
dist[i] = 5000005;
priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> pq;
pq.push({0, 0, 0});
while (pq.size())
{
auto [cost, tim, node] = pq.top();
pq.pop();
if (cost > dist[node])
continue;
dist[node] = cost;
for (auto [l, r, y, c] : adj[node])
if (l >= tim && cost + c < dist[y])
pq.push({cost + c, r, y});
}
return (dist[n - 1] == 5000005 ? -1 : dist[n - 1]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |