Submission #1130323

#TimeUsernameProblemLanguageResultExecution timeMemory
1130323am_aadvikOlympic Bus (JOI20_ho_t4)C++17
5 / 100
1101 ms181264 KiB
#include <iostream> #include<set> #include<map> #include<vector> #define int long long const int inf = 1e17; using namespace std; vector<vector<int>> g[2][205]; vector<vector<int>> dist[2]; //path, node, rev. edg set<vector<int>> q; //{dist+cost, node, path, rev. edg.} vector<int> f; int path(int s, int t, int n, int m) { dist[0].assign(n + 1, vector<int>(m + 1, inf)); dist[1].assign(n + 1, vector<int>(m + 1, inf)); q.insert({ 0, s, 0, 0 }), dist[0][s][0] = 0; while (q.size()) { f = *q.begin(); q.erase(q.begin()); if (f[2] && (f[1] == s)) { //complete! q.clear(); return f[0]; } if (f[1] == t) f[2] = 1; //1 way complete! for (auto x : g[0][f[1]]) { //out edgs. if (f[3] != x[3]) { //this edg. wasnt rev. int val = dist[f[2]][x[0]][f[3]]; if (val > (f[0] + x[1])) { if (val != inf) q.erase({ val, x[0], f[2], f[3] }); dist[f[2]][x[0]][f[3]] = (f[0] + x[1]); q.insert({ (f[0] + x[1]), x[0], f[2], f[3] }); } } } for (auto x : g[1][f[1]]) { //in edgs. if (f[3] == x[3]) { //this edge was rev. int val = dist[f[2]][x[0]][f[3]]; if (val > (f[0] + x[1])) { if (val != inf) q.erase({ val, x[0], f[2], f[3] }); dist[f[2]][x[0]][f[3]] = (f[0] + x[1]); q.insert({ (f[0] + x[1]), x[0], f[2], f[3] }); } } else if ((f[3] == 0) && (!f[2])) { f[3] = x[3]; int val = dist[f[2]][x[0]][f[3]]; if (val > (f[0] + x[1] + x[2])) { if (val != inf) q.erase({ val, x[0], f[2], f[3] }); dist[f[2]][x[0]][f[3]] = (f[0] + x[1] + x[2]); q.insert({ (f[0] + x[1] + x[2]), x[0], f[2], f[3] }); } f[3] = 0; } } } return inf; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { int u, v, c, d; cin >> u >> v >> c >> d; g[0][u].push_back({ v, c ,d, i }); g[1][v].push_back({ u, c, d, i }); } int ans = min(path(1, n, n, m), path(n, 1, n, m)); cout << ((ans == inf) ? -1 : ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...