# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988076 |
2024-05-24T04:05:33 Z |
michified |
Robot (JOI21_ho_t4) |
C++17 |
|
1330 ms |
111572 KB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct state_t {
int id, inc;
ll cost, inw;
};
struct edge_t {
int to, col;
ll cost;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
auto cmp = [](const state_t& a, const state_t& b){return a.cost > b.cost;};
priority_queue<state_t, vector<state_t>, decltype(cmp)> pq(cmp);
int n, m, i, tu, tv, tw, tc;
cin >> n >> m;
vector<vector<edge_t>> adj(n + 1);
vector<unordered_map<int, ll>> coltot(n + 1);
vector<unordered_map<int, vector<edge_t>>> c2e(n + 1);
for (i = 0; i < m; i++) {
cin >> tu >> tv >> tc >> tw;
adj[tu].push_back({tv, tc, tw});
adj[tv].push_back({tu, tc, tw});
coltot[tu][tc] += tw;
coltot[tv][tc] += tw;
c2e[tu][tc].push_back({tv, tc, tw});
c2e[tv][tc].push_back({tu, tc, tw});
}
vector<map<int, ll>> best(n + 1);
pq.push({1, 0, 0, 0});
best[1][0] = 0;
while (not pq.empty()) {
state_t cur = pq.top();
pq.pop();
if (cur.id == n and cur.inc == 0) {
cout << cur.cost;
return 0;
}
if (cur.cost > best[cur.id][cur.inc]) continue;
if (cur.inc == 0) {
for (edge_t& e : adj[cur.id]) {
ll tmp = cur.cost + coltot[cur.id][e.col] - e.cost;
if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) {
pq.push({e.to, 0, tmp, 0});
best[e.to][0] = tmp;
}
tmp = cur.cost;
if (best[e.to].find(e.col) == best[e.to].end() or best[e.to][e.col] > tmp) {
pq.push({e.to, e.col, tmp, e.cost});
best[e.to][e.col] = tmp;
}
}
} else {
ll tmp = cur.cost + cur.inw;
if (best[cur.id].find(0) == best[cur.id].end() or best[cur.id][0] > tmp) {
pq.push({cur.id, 0, tmp, 0});
best[cur.id][0] = tmp;
}
for (edge_t& e : c2e[cur.id][cur.inc]) {
tmp = cur.cost + coltot[cur.id][e.col] - e.cost;
if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) {
pq.push({e.to, 0, tmp, 0});
best[e.to][0] = tmp;
}
}
}
}
cout << -1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
31492 KB |
Output is correct |
2 |
Correct |
70 ms |
17160 KB |
Output is correct |
3 |
Correct |
128 ms |
27336 KB |
Output is correct |
4 |
Correct |
129 ms |
23628 KB |
Output is correct |
5 |
Correct |
1330 ms |
111572 KB |
Output is correct |
6 |
Correct |
827 ms |
101332 KB |
Output is correct |
7 |
Correct |
536 ms |
87080 KB |
Output is correct |
8 |
Correct |
877 ms |
85812 KB |
Output is correct |
9 |
Correct |
872 ms |
85944 KB |
Output is correct |
10 |
Correct |
469 ms |
55660 KB |
Output is correct |
11 |
Correct |
195 ms |
49416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |