Submission #444703

#TimeUsernameProblemLanguageResultExecution timeMemory
444703dutchRobot (JOI21_ho_t4)C++17
0 / 100
3074 ms34256 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; const int LIM = 1e5, INF = 1e18; int n, m, a[4][2*LIM], d[5*LIM]; map<int, vector<array<int, 2>>> g[LIM]; map<int, int> s[LIM]; set<array<int, 2>> q; void add(int i, int j){ if(d[i] > j){ if(d[i] < INF) q.erase({d[i], i}); q.insert({-(d[i] = j), i}); } } signed main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for(int i=0; i<m; ++i){ for(int j=0; j<4; ++j) cin >> a[j][i]; --a[0][i], --a[1][i]; g[a[0][i]][a[2][i]].push_back({a[1][i], i}); g[a[1][i]][a[2][i]].push_back({a[0][i], i}); s[a[0][i]][a[2][i]] += a[3][i]; s[a[1][i]][a[2][i]] += a[3][i]; } fill(d, d+n+m*2, INF); q.insert({d[0] = 0, 0}); int ans = INF; while(!q.empty()){ int dist = -(*q.begin())[0], u = (*q.begin())[1]; q.erase(q.begin()); if(dist != d[u]) continue; if(u>=n){ int f = (u -= n) % m; u = a[u >= m][f]; for(auto &[v, e] : g[u][a[2][f]]) if(e != f) add(v, dist + s[u][a[2][e]] - a[3][e] - a[3][f]); } for(auto &[z, h] : g[u]){ for(auto &[v, e] : h){ add(v, dist + s[u][a[2][e]] - a[3][e]); add(n+e+m*(u == a[0][e]), dist + a[3][e]); } } if(u == n-1) ans = min(ans, dist); } cout << (ans == INF ? -1 : ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...