제출 #891890

#제출 시각아이디문제언어결과실행 시간메모리
891890oblantisCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
2063 ms262144 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, int> pdi; const ll inf = 1e14 + 10000; const int mod = 1e9+7; const int maxn = 5e5 + 12; vt<pii> g[maxn]; void ope(vll &a, int st){ a[st] = 0; priority_queue<pair<ll, int>, vt<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.push({0, st}); while(!pq.empty()){ pair<ll, int> nw = pq.top(); pq.pop(); if(a[nw.ss] != nw.ff)continue; for(auto i : g[nw.ss]){ if(nw.ff + i.ss < a[i.ff]) { a[i.ff] = nw.ff + i.ss; pq.push({a[i.ff], i.ff}); } } } } void solve() { int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for(int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; g[a].pb({b, c}); g[b].pb({a, c}); } s--, t--, u--, v--; vll a(n, inf), b(n, inf), c(n, inf), d(n, inf); ope(a, s), ope(b, t), ope(c, u), ope(d, v); queue<tuple<int, ll, ll>> q; q.push({t, c[t], d[t]}); ll ans = d[u]; while(!q.empty()){ tuple<int, ll, ll> nw = q.front(); ans = min(ans, get<1>(nw) + get<2>(nw)); q.pop(); for(auto i : g[get<0>(nw)]){ if(a[i.ff] + i.ss == a[get<0>(nw)]){ q.push({i.ff, min(get<1>(nw), c[i.ff]), min(get<2>(nw), d[i.ff])}); } } } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int times = 1; //cin >> times; for(int i = 1; i <= times; i++) { 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...