Submission #1158063

#TimeUsernameProblemLanguageResultExecution timeMemory
1158063vladiliusRobot (JOI21_ho_t4)C++20
0 / 100
3093 ms47732 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define arr3 array<int, 3> #define arr4 array<ll, 4> int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; vector<arr3> g[n + 1]; vector<map<int, int>> mp(n + 1); while (m--){ int x, y, c, w; cin>>x>>y>>c>>w; g[x].pb({y, c, w}); g[y].pb({x, c, w}); mp[x][c]++; mp[y][c]++; } priority_queue<arr4, vector<arr4>, greater<arr4>> q; q.push({0, 1, 0, 0}); vector<map<pair<int, bool>, ll>> dist(n + 1); dist[1][{0, 0}] = 0; while (!q.empty()){ auto [ds, v, k, P] = q.top(); q.pop(); for (auto [u, c, w]: g[v]){ int cc = mp[v][c] - (c == k); ll f = ds + w; if (dist[u].find({v, 1}) == dist[u].end()){ dist[u][{v, 1}] = f; q.push({f, u, c, v}); } else if (f < dist[u][{v, 1}]){ dist[u][{v, 1}] = f; q.push({f, u, c, v}); } if (u == P && k){ assert(c == k); if (dist[u].find({v, 1}) == dist[u].end()){ dist[u][{v, 1}] = ds; q.push({ds, u, k, v}); } else if (ds < dist[u][{v, 1}]){ dist[u][{v, 1}] = ds; q.push({ds, u, k, v}); } } if (cc <= 1){ ll f = ds; if (dist[u].find({v, 0}) == dist[u].end()){ dist[u][{v, 0}] = f; q.push({f, u, 0, v}); } else if (f < dist[u][{v, 0}]){ dist[u][{v, 0}] = f; q.push({f, u, 0, v}); } } } } if (dist[n].empty()){ cout<<-1<<"\n"; } else { ll out = 1e18; for (auto [x, y]: dist[n]) out = min(out, y); cout<<out<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...