제출 #971227

#제출 시각아이디문제언어결과실행 시간메모리
971227vyshniak_nCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
831 ms73808 KiB
#include <iostream> #include <cmath> #include <algorithm> #include <stdio.h> #include <cstdint> #include <cstring> #include <string> #include <cstdlib> #include <vector> #include <bitset> #include <map> #include <queue> #include <ctime> #include <stack> #include <set> #include <list> #include <random> #include <deque> #include <functional> #include <iomanip> #include <sstream> #include <fstream> #include <complex> #include <numeric> #include <cassert> #include <array> #include <tuple> #include <unordered_map> #include <unordered_set> #include <thread> typedef long long ll; typedef long double ld; using namespace std; #define el '\n' #define ff first #define ss second #define pb push_back #define popb pop_back #define point pair <ll, ll> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() const ll N = 1e5 + 10; const ll INF = 2e18 + 10; const ll inf = 2e9 + 10; vector <point> gr[N], ngr[3 * N]; ll dist[4][3 * N], tin[N], timer = 0; void solve() { ll n, m; cin >> n >> m; ll s, t, u, v; cin >> s >> t >> u >> v; ll a[m], b[m], c[m]; for (ll i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i]; gr[a[i]].pb(make_pair(b[i], c[i])); gr[b[i]].pb(make_pair(a[i], c[i])); } set <point> st; for (ll i = 1; i <= 3 * n; i++) dist[0][i] = dist[1][i] = dist[2][i] = dist[3][i] = INF; st.insert({0, s}); dist[0][s] = 0; while (!st.empty()) { ll ver = st.begin()->ss; st.erase(st.begin()); tin[ver] = ++timer; for (point to : gr[ver]) { if (dist[0][to.ff] > dist[0][ver] + to.ss) { st.erase(make_pair(dist[0][to.ff], to.ff)); dist[0][to.ff] = dist[0][ver] + to.ss; st.insert(make_pair(dist[0][to.ff], to.ff)); } } } st.insert({0, t}); dist[1][t] = 0; while (!st.empty()) { ll ver = st.begin()->ss; st.erase(st.begin()); for (point to : gr[ver]) { if (dist[1][to.ff] > dist[1][ver] + to.ss) { st.erase(make_pair(dist[1][to.ff], to.ff)); dist[1][to.ff] = dist[1][ver] + to.ss; st.insert(make_pair(dist[1][to.ff], to.ff)); } } } ll way = dist[0][t]; for (ll i = 0; i < m; i++) { if (tin[a[i]] > tin[b[i]]) swap(a[i], b[i]); ngr[a[i]].pb(make_pair(b[i], c[i])); ngr[b[i]].pb(make_pair(a[i], c[i])); ngr[a[i] + 2 * n].pb(make_pair(b[i] + 2 * n, c[i])); ngr[b[i] + 2 * n].pb(make_pair(a[i] + 2 * n, c[i])); if (dist[0][a[i]] + c[i] + dist[1][b[i]] == way) ngr[a[i] + n].pb(make_pair(b[i] + n, 0)); } for (ll i = 1; i <= n; i++) { ngr[i].pb(make_pair(i + n, 0)); ngr[i + n].pb(make_pair(i + 2 * n, 0)); } st.insert({0, u}); dist[2][u] = 0; while (!st.empty()) { ll ver = st.begin()->ss; st.erase(st.begin()); for (point to : ngr[ver]) { if (dist[2][to.ff] > dist[2][ver] + to.ss) { st.erase(make_pair(dist[2][to.ff], to.ff)); dist[2][to.ff] = dist[2][ver] + to.ss; st.insert(make_pair(dist[2][to.ff], to.ff)); } } } st.insert({0, v}); dist[3][v] = 0; while (!st.empty()) { ll ver = st.begin()->ss; st.erase(st.begin()); for (point to : ngr[ver]) { if (dist[3][to.ff] > dist[3][ver] + to.ss) { st.erase(make_pair(dist[3][to.ff], to.ff)); dist[3][to.ff] = dist[3][ver] + to.ss; st.insert(make_pair(dist[3][to.ff], to.ff)); } } } cout << min(dist[2][v + 2 * n], dist[3][u + 2 * n]) << el; return; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tests = 1; //cin >> tests; while (tests--) solve(); 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...