Submission #925312

#TimeUsernameProblemLanguageResultExecution timeMemory
925312crafticatRobot (JOI21_ho_t4)C++17
34 / 100
3059 ms160464 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll,ll>; constexpr ll inf = 1e12 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n, m; cin >> n >> m; vector<vector<tuple<ll,ll,ll>>> f(n + 1); for (ll i = 0; i < m; ++i) { ll a, b, c, d; cin >> a >> b >> c >> d; f[a].emplace_back(c,b,d); f[b].emplace_back(c,a,d); } vector<vector<tuple<ll,ll,ll>>> g(n + 1); vector<map<ll,ll>> apps(n + 1); map<pii, pii> roads; for (ll i = 1; i <= n; ++i) { map<ll, ll> app; for (auto [c, node, d] : f[i]) { app[c]+=d; } apps[i] = app; for (auto [c, node, d] : f[i]) { roads[{i,node}] = {c,d}; roads[{node,i}] = {c,d}; g[i].emplace_back(node,d,c); } } priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<>> pq; pq.emplace(0,1,0); vector<ll> d(n + 1,inf); map<tuple<ll,ll>,bool> visited; while (!pq.empty()) { auto [cost, cur, par] = pq.top();pq.pop(); if (visited[{cur,par}]) continue; d[cur] = min(d[cur],cost); visited[{cur,par}] = true; for (auto [child, len, c] : g[cur]) { if (child == par) continue; if (visited[{child,cur}]) continue; ll am = apps[cur][c]; if (c == roads[{par,cur}].first) am -= roads[{par,cur}].second; pq.emplace(cost + len,child,cur); pq.emplace(cost + am - len,child,-cur); } } if (d[n] == inf) { cout << "-1"; return 0; } cout << d[n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...