Submission #880537

#TimeUsernameProblemLanguageResultExecution timeMemory
880537codexistentCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
360 ms22880 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define MAXN 100005 vector<long long> sp1 (int N, vector<vector<pair<int, int> > > const &E, int r){ priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > pq; pq.push(make_pair(0, r)); bool V[N] = {false}; vector<long long> D; D.resize(N); fill(begin(D), end(D), LONG_LONG_MAX); D[r] = 0; while(!pq.empty()){ int n = pq.top().second; pq.pop(); if(V[n]) continue; for(auto e : E[n]) if(D[e.first] > D[n] + e.second) { D[e.first] = D[n] + e.second; pq.push(make_pair(D[e.first], e.first)); } } return D; } vector<pair<long long, long long> > sp2 (int N, vector<vector<pair<int, int> > > const &E, vector<long long> const &BD, int r){ priority_queue<pair<pair<long long, long long>, int>, vector<pair<pair<long long, long long>, int> >, greater<pair<pair<long long, long long>, int> > > pq; pq.push(make_pair(make_pair(0, BD[r]), r)); bool V[N] = {false}; vector<pair<long long, long long> > D; D.resize(N); fill(begin(D), end(D), make_pair(LONG_LONG_MAX, LONG_LONG_MAX)); D[r] = make_pair(0, BD[r]); while(!pq.empty()){ int n = pq.top().second; pq.pop(); if(V[n]) continue; for(auto e : E[n]) if(D[e.first] > make_pair(D[n].first + e.second, min(D[n].second, BD[e.first]))) { D[e.first] = make_pair(D[n].first + e.second, min(D[n].second, BD[e.first])); pq.push(make_pair(D[e.first], e.first)); } } return D; } int main(){ int N, M, S, T, U, V; cin >> N >> M; cin >> S >> T >> U >> V; S--, T--, U--, V--; vector<vector<pair<int, int> > > E; E.resize(N); FOR(i, 1, M){ int a, b, w; cin >> a >> b >> w; a--, b--; E[a].push_back(make_pair(b, w)), E[b].push_back(make_pair(a, w)); } cout << V << endl; vector<long long> UD = sp1(N, E, U), VD = sp1(N, E, V); vector<pair<long long, long long> > SD = sp2(N, E, VD, S), TD = sp2(N, E, VD, T); pair<long long, long long> R = make_pair(LONG_LONG_MAX, LONG_LONG_MAX); FOR(i, 0, N - 1) { R = min(R, make_pair(SD[i].first + TD[i].first, UD[i] + min(SD[i].second, TD[i].second))); } cout << R.second; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...