# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
385495 |
2021-04-04T13:39:54 Z |
ngpin04 |
Robot (JOI21_ho_t4) |
C++14 |
|
3000 ms |
31440 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
struct edge {
int v,pos,c,cost;
edge(){}
edge(int _v, int _pos, int _c, int _cost) {
v = _v;
pos = _pos;
c = _c;
cost = _cost;
}
};
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const long long oo = 1e18;
vector <edge> adj[N];
vector <long long> dis[N];
long long sum[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, adj[v].size(), c, w);
edge b = edge(u, adj[u].size(), c, w);
adj[u].push_back(a);
adj[v].push_back(b);
}
for (int i = 1; i <= n; i++)
dis[i].assign(adj[i].size() + 1, oo);
priority_queue <pair <long long, pair <int, int>>> heap;
heap.push(mp(0, mp(1, adj[1].size())));
dis[1][adj[1].size()] = 0;
while (heap.size()) {
int u = heap.top().se.fi;
int id = heap.top().se.se;
long long cur = -heap.top().fi;
heap.pop();
if (cur != dis[u][id])
continue;
//cerr << u << " " << id << endl;
for (int i = 0; i < (int) adj[u].size(); i++) if (i != id) {
edge e = adj[u][i];
sum[e.c] += e.cost;
}
for (int i = 0; i < (int) adj[u].size(); i++) if (i != id) {
edge e = adj[u][i];
int v = e.v;
int c = e.c;
int pos = e.pos;
int cost = e.cost;
if (mini(dis[v][pos], cur + cost))
heap.push(mp(-dis[v][pos], mp(v, pos)));
if (mini(dis[v][adj[v].size()], cur + sum[c] - cost))
heap.push(mp(-dis[v][adj[v].size()], mp(v, adj[v].size())));
}
for (edge e : adj[u])
sum[e.c] = 0;
}
long long ans = oo;
for (long long res : dis[n])
ans = min(ans, res);
if (ans == oo)
ans = -1;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
6 ms |
5100 KB |
Output is correct |
3 |
Correct |
5 ms |
5100 KB |
Output is correct |
4 |
Correct |
6 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
5 ms |
5228 KB |
Output is correct |
8 |
Correct |
5 ms |
5100 KB |
Output is correct |
9 |
Correct |
29 ms |
5356 KB |
Output is correct |
10 |
Correct |
22 ms |
5484 KB |
Output is correct |
11 |
Correct |
34 ms |
5356 KB |
Output is correct |
12 |
Correct |
18 ms |
5484 KB |
Output is correct |
13 |
Correct |
34 ms |
5356 KB |
Output is correct |
14 |
Correct |
36 ms |
5356 KB |
Output is correct |
15 |
Correct |
5 ms |
5100 KB |
Output is correct |
16 |
Correct |
7 ms |
5228 KB |
Output is correct |
17 |
Correct |
6 ms |
5228 KB |
Output is correct |
18 |
Correct |
5 ms |
5100 KB |
Output is correct |
19 |
Correct |
8 ms |
5356 KB |
Output is correct |
20 |
Correct |
6 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
16224 KB |
Output is correct |
2 |
Correct |
53 ms |
9324 KB |
Output is correct |
3 |
Correct |
269 ms |
20448 KB |
Output is correct |
4 |
Correct |
89 ms |
12000 KB |
Output is correct |
5 |
Execution timed out |
3091 ms |
31440 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
6 ms |
5100 KB |
Output is correct |
3 |
Correct |
5 ms |
5100 KB |
Output is correct |
4 |
Correct |
6 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
5 ms |
5228 KB |
Output is correct |
8 |
Correct |
5 ms |
5100 KB |
Output is correct |
9 |
Correct |
29 ms |
5356 KB |
Output is correct |
10 |
Correct |
22 ms |
5484 KB |
Output is correct |
11 |
Correct |
34 ms |
5356 KB |
Output is correct |
12 |
Correct |
18 ms |
5484 KB |
Output is correct |
13 |
Correct |
34 ms |
5356 KB |
Output is correct |
14 |
Correct |
36 ms |
5356 KB |
Output is correct |
15 |
Correct |
5 ms |
5100 KB |
Output is correct |
16 |
Correct |
7 ms |
5228 KB |
Output is correct |
17 |
Correct |
6 ms |
5228 KB |
Output is correct |
18 |
Correct |
5 ms |
5100 KB |
Output is correct |
19 |
Correct |
8 ms |
5356 KB |
Output is correct |
20 |
Correct |
6 ms |
5228 KB |
Output is correct |
21 |
Correct |
153 ms |
16224 KB |
Output is correct |
22 |
Correct |
53 ms |
9324 KB |
Output is correct |
23 |
Correct |
269 ms |
20448 KB |
Output is correct |
24 |
Correct |
89 ms |
12000 KB |
Output is correct |
25 |
Execution timed out |
3091 ms |
31440 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |