# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
476735 |
2021-09-28T12:12:52 Z |
tranxuanbach |
Robot (JOI21_ho_t4) |
C++17 |
|
912 ms |
108800 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;
const int N = 1e5 + 5, M = 2e5 + 5;
struct Edge{
int u, v, c, p;
Edge(){
}
Edge(int u, int v, int c, int p): u(u), v(v), c(c), p(p){
}
};
int n, m;
Edge edges[2 * M];
vi adj[N];
unordered_map <int, vi> mppc[N];
unordered_map <int, ll> mppsp[N];
unordered_map <int, ll> distc[N];
ll dist[N];
priority_queue <tuple <ll, int, int>, vector <tuple <ll, int, int>>, greater <tuple <ll, int, int>>> pq;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("KEK.inp", "r", stdin);
// freopen("KEK.out", "w", stdout);
cin >> n >> m;
ForE(i, 1, m){
int u, v, c, p; cin >> u >> v >> c >> p;
edges[2 * i - 1] = Edge(u, v, c, p);
edges[2 * i] = Edge(v, u, c, p);
adj[u].emplace_back(2 * i - 1);
adj[v].emplace_back(2 * i);
}
memset(dist, 0x3f, sizeof(dist));
ForE(i, 1, 2 * m){
mppc[edges[i].u][edges[i].c].emplace_back(i);
mppsp[edges[i].u][edges[i].c] += edges[i].p;
distc[edges[i].u][edges[i].c] = dist[0];
}
dist[1] = 0; pq.emplace(dist[1], 1, 0);
while (!pq.empty()){
ll d; int u, c; tie(d, u, c) = pq.top(); pq.pop();
if (!c){
if (d != dist[u]){
continue;
}
Fora(elem, mppc[u]){
if (isz(elem.se) == 1){
int i = elem.se[0];
if (dist[edges[i].v] > d){
dist[edges[i].v] = d;
pq.emplace(dist[edges[i].v], edges[i].v, 0);
}
}
Fora(i, elem.se){
if (dist[edges[i].v] > d + edges[i].p){
dist[edges[i].v] = d + edges[i].p;
pq.emplace(dist[edges[i].v], edges[i].v, 0);
}
if (distc[edges[i].v][edges[i].c] > d){
distc[edges[i].v][edges[i].c] = d;
pq.emplace(d, edges[i].v, edges[i].c);
}
}
}
}
else{
if (d != distc[u][c]){
continue;
}
if (isz(mppc[u][c]) == 1){
continue;
}
Fora(i, mppc[u][c]){
if (dist[edges[i].v] > distc[u][c] + mppsp[u][c] - edges[i].p){
dist[edges[i].v] = distc[u][c] + mppsp[u][c] - edges[i].p;
pq.emplace(dist[edges[i].v], edges[i].v, 0);
}
}
}
}
cout << (dist[n] == dist[0] ? -1 : dist[n]) << endl;
}
/*
==================================================+
INPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19788 KB |
Output is correct |
2 |
Correct |
11 ms |
19888 KB |
Output is correct |
3 |
Correct |
12 ms |
19888 KB |
Output is correct |
4 |
Correct |
11 ms |
19788 KB |
Output is correct |
5 |
Correct |
11 ms |
19916 KB |
Output is correct |
6 |
Correct |
11 ms |
19916 KB |
Output is correct |
7 |
Incorrect |
15 ms |
20044 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
42596 KB |
Output is correct |
2 |
Correct |
110 ms |
32156 KB |
Output is correct |
3 |
Correct |
310 ms |
40556 KB |
Output is correct |
4 |
Correct |
214 ms |
38320 KB |
Output is correct |
5 |
Correct |
912 ms |
108800 KB |
Output is correct |
6 |
Correct |
884 ms |
98732 KB |
Output is correct |
7 |
Correct |
495 ms |
84436 KB |
Output is correct |
8 |
Correct |
576 ms |
79828 KB |
Output is correct |
9 |
Correct |
631 ms |
79892 KB |
Output is correct |
10 |
Correct |
476 ms |
63504 KB |
Output is correct |
11 |
Correct |
230 ms |
61800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19788 KB |
Output is correct |
2 |
Correct |
11 ms |
19888 KB |
Output is correct |
3 |
Correct |
12 ms |
19888 KB |
Output is correct |
4 |
Correct |
11 ms |
19788 KB |
Output is correct |
5 |
Correct |
11 ms |
19916 KB |
Output is correct |
6 |
Correct |
11 ms |
19916 KB |
Output is correct |
7 |
Incorrect |
15 ms |
20044 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |