| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 806650 | vjudge1 | Robot (JOI21_ho_t4) | C++17 | 84 ms | 9956 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 100100;
struct edge{
int b, c, p;
};
vector < edge > adj[N];
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int a, b, c, p; m --> 0;) {
cin >> a >> b >> c >> p;
adj[a].push_back({b, c, p});
adj[b].push_back({a, c, p});
}
for(int i = 1; i <= n; ++i) {
sort(adj[i].begin(), adj[i].end(), [&](edge a, edge b) {
return a.c < b.c;
});
}
priority_queue < pair < int, int > > pq;
vector < ll > dist(n + 1, 1e18);
dist[1] = 0;
pq.push({0, 1});
for(; !pq.empty();) {
auto [dst, v] = pq.top();
pq.pop();
if(-dst > dist[v]) {
continue;
}
for(int i = 0; i < adj[v].size(); ++ i) {
int tmp = ((i && adj[v][i - 1].c == adj[v][i].c)||
(i + 1 < adj[v].size() && adj[v][i].c == adj[v][i + 1].c) ? adj[v][i].p : 0);
int u = adj[v][i].b;
if(dist[v] + tmp < dist[u]) {
dist[u] = dist[v] + tmp;
pq.push({-dist[u], u});
}
}
}
cout << (dist[n] == 1e18 ? -1 : dist[n]);
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
