이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2e5+5;
const ll INF = 5e15;
vector<array<int, 4>> adj[N];
ll dist[N];
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] = INF;
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] == INF ? -1 : dist[n-1]);
}
#ifdef MUAATH_5
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cout << solve(3, 3, 0, {20, 30, 40}, {0, 1, 0}, {1, 2, 2}, {1, 20, 18}, {15, 30, 40}, {10, 5, 40}, {16}, {19}) << '\n';
cout << solve(3, 5, 6, {30, 38, 33}, {0, 1, 0, 0, 1}, {2, 0, 1, 2, 2}, {12, 48, 26, 6, 49}, {16, 50, 28, 7, 54}, {38, 6, 23, 94, 50}, {32, 14, 42, 37, 2, 4}, {36, 14, 45, 40, 5, 5}) << '\n';
int _;
cin >> _;
while (_--) {
int n, m, w;
cin >> n >> m >> w;
vector<int> t(n), x(m), y(m), a(m), b(m), c(m), l(w), r(w);
for (int &i : t)
cin >> i;
for (int i = 0; i < m; i++) {
cin >> x[i] >> y[i] >> a[i] >> b[i] >> c[i];
}
for (int i = 0; i < w; i++) {
cin >> l[i] >> r[i];
}
cout << solve(n, m, w, t, x, y, a, b, c, l, r) << '\n';
}
}
#endif
# | 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... |