# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
515741 |
2022-01-19T14:54:38 Z |
Nghes |
Robot (JOI21_ho_t4) |
C++14 |
|
131 ms |
17748 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
struct edge {
int v,c,cost;
edge(){}
edge(int _v, int _c, int _cost) {
v = _v;
c = _c;
cost = _cost;
}
};
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const long long oo = 1e18;
vector <edge> adj[N];
long long dis[2 * N];
long long sum[M];
long long best[M];
int n,m;
template <typename T>
bool mini(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u,v,c,w;
cin >> u >> v >> c >> w;
edge a = edge(v, c, w);
edge b = edge(u, c, w);
adj[u].push_back(a);
adj[v].push_back(b);
}
for (int i = 1; i <= n; i++)
dis[i] = oo;
for (int i = 1; i <= m; i++)
best[i] = oo;
dis[1] = 0;
priority_queue <pair <long long, int>> heap;
heap.push(mp(0, 1));
while (heap.size()) {
int u = heap.top().se;
long long cur = -heap.top().fi;
heap.pop();
if (cur != dis[u])
continue;
for (edge e : adj[u]) {
sum[e.c] += e.cost;
best[e.c] = min(best[e.c], dis[e.v]);
}
for (edge e : adj[u]) {
int v = e.v;
int c = e.c;
int w = e.cost;
long long tmp = min(0LL + w, sum[c] - w);
if (mini(dis[v], cur + tmp))
heap.push(mp(-dis[v], v));
// if (mini(dis[v], best[c] + sum[c] - w))
// heap.push(mp(-dis[v], v));
}
for (edge e : adj[u]) {
sum[e.c] = 0;
best[e.c] = oo;
}
}
if (dis[n] == oo)
dis[n] = -1;
cout << dis[n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2656 KB |
Output is correct |
2 |
Correct |
3 ms |
2672 KB |
Output is correct |
3 |
Correct |
2 ms |
2672 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Incorrect |
3 ms |
2728 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
8560 KB |
Output is correct |
2 |
Correct |
20 ms |
5356 KB |
Output is correct |
3 |
Correct |
62 ms |
12100 KB |
Output is correct |
4 |
Correct |
27 ms |
6700 KB |
Output is correct |
5 |
Incorrect |
131 ms |
17748 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2656 KB |
Output is correct |
2 |
Correct |
3 ms |
2672 KB |
Output is correct |
3 |
Correct |
2 ms |
2672 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Incorrect |
3 ms |
2728 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |