Submission #364906

#TimeUsernameProblemLanguageResultExecution timeMemory
364906NachoLibreCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
727 ms25308 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, s, t, u, o; long long us[N], os[N]; vector<pair<int, int>> v[N]; vector<long long> sd, td, ud, od; vector<long long> D(int x) { vector<long long> d(n + 1, -1); set<pair<long long, int>> s; d[x] = 0; s.insert({0, x}); while(s.size()) { int y = s.begin()->second; s.erase(s.begin()); for(auto a : v[y]) { if(d[a.first] == -1 || d[a.first] > d[y] + a.second) { if(d[a.first] != -1) s.erase(s.find({d[a.first], a.first})); d[a.first] = d[y] + a.second; s.insert({d[a.first], a.first}); } } } return d; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> s >> t >> u >> o; for(int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; v[x].push_back({y, z}); v[y].push_back({x, z}); } sd = D(s); td = D(t); ud = D(u); od = D(o); vector<pair<long long, int>> ve; for(int i = 1; i <= n; ++i) { ve.push_back({sd[i], i}); } sort(ve.begin(), ve.end()); long long fp = ud[o]; for(auto a : ve) { us[a.second] = ud[a.second]; os[a.second] = od[a.second]; for(auto b : v[a.second]) { if(sd[b.first] + b.second == sd[a.second]) { us[a.second] = min(us[a.second], us[b.first]); os[a.second] = min(os[a.second], os[b.first]); } } if(sd[a.second] + td[a.second] == sd[t]) fp = min(fp, min(us[a.second] + od[a.second], os[a.second] + ud[a.second])); } cout << fp << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...