# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
489300 |
2021-11-22T07:29:42 Z |
Jarif_Rahman |
Robot (JOI21_ho_t4) |
C++17 |
|
698 ms |
100068 KB |
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e17;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<vector<array<int, 3>>> v(n);
for(int i = 0; i < m; i++){
int a, b, c, p; cin >> a >> b >> c >> p; a--, b--;
v[a].pb({b, c, p});
v[b].pb({a, c, p});
}
vector<pair<int, int>> nodes;
map<pair<int, int>, int> node_id;
for(int i = 0; i < n; i++) nodes.pb({i, -1});
for(int i = 0; i < n; i++){
for(auto [x, c, p]: v[i]) nodes.pb({i, x});
}
for(int i = 0; i < nodes.size(); i++) node_id[nodes[i]] = i;
vector<vector<pair<int, ll>>> g(nodes.size());
for(int i = 0; i < n; i++){
unordered_map<int, ll> cost;
for(auto [x, c, p]: v[i]) cost[c]+=p;
for(auto [x, c, p]: v[i]){
g[i].pb({x, min((ll)p, cost[c]-p)});
g[i].pb({node_id[{x, i}], p});
}
}
for(int i = 0; i < n; i++){
unordered_map<int, vector<pair<int, int>>> mp;
for(auto [x, c, p]: v[i]) mp[c].pb({p, x});
for(auto [cc, ss]: mp){
if(ss.size() < 2) continue;
sort(ss.rbegin(), ss.rend());
ll s = 0;
for(auto [p, x]: ss) s+=p;
for(int j = 0; j < ss.size(); j++){
ll cur = s-ss[j].f;
if(j == 0){
cur-ss[1].f;
g[node_id[{i, ss[j].sc}]].pb({ss[1].sc, cur});
}
else{
cur-=ss[0].f;
g[node_id[{i, ss[j].sc}]].pb({ss[0].sc, cur});
}
}
}
}
vector<ll> dis(nodes.size(), inf);
vector<bool> bl(nodes.size(), 0);
priority_queue<pair<ll, int>> pq;
dis[0] = 0;
pq.push({0, 0});
while(!pq.empty()){
int nd = pq.top().sc; pq.pop();
if(bl[nd]) continue;
bl[nd] = 1;
for(auto [x, w]: g[nd]) if(dis[nd]+w < dis[x]){
dis[x] = dis[nd]+w;
pq.push({-dis[x], x});
}
}
ll ans = inf;
for(int i = 0; i < nodes.size(); i++) if(nodes[i].f == n-1) ans = min(ans, dis[i]);
if(ans >= inf) ans = -1;
cout << ans << "\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < nodes.size(); i++) node_id[nodes[i]] = i;
| ~~^~~~~~~~~~~~~~
Main.cpp:43:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j = 0; j < ss.size(); j++){
| ~~^~~~~~~~~~~
Main.cpp:46:24: warning: value computed is not used [-Wunused-value]
46 | cur-ss[1].f;
| ^
Main.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 0; i < nodes.size(); i++) if(nodes[i].f == n-1) ans = min(ans, dis[i]);
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
1296 KB |
Output is correct |
10 |
Incorrect |
4 ms |
1216 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
38264 KB |
Output is correct |
2 |
Correct |
93 ms |
17320 KB |
Output is correct |
3 |
Correct |
382 ms |
63512 KB |
Output is correct |
4 |
Correct |
150 ms |
25764 KB |
Output is correct |
5 |
Correct |
698 ms |
100068 KB |
Output is correct |
6 |
Correct |
639 ms |
93644 KB |
Output is correct |
7 |
Incorrect |
614 ms |
95752 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
1296 KB |
Output is correct |
10 |
Incorrect |
4 ms |
1216 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |