제출 #1167206

#제출 시각아이디문제언어결과실행 시간메모리
1167206Valters07Commuter Pass (JOI18_commuter_pass)C++20
31 / 100
229 ms15316 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #define fio ios_base::sync_with_stdio(0);cin.tie(0); #define ll long long #define ld long double #define en exit(0); #define pb push_back #define fi first #define se second using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e5+5; const ll INF = 1e18+5; vector<pair<int,int> > g[N]; bool mark[N]; vector<ll> dijkstra(int st, int n) { vector<ll> dist(n+1,INF); vector<bool> vis(n+1); priority_queue<pair<ll,int> > q; dist[st]=0; q.push({0,st}); while(!q.empty()) { int u = q.top().se; q.pop(); if(vis[u]) continue; vis[u]=1; for(auto [v,w]:g[u]) { ll nwd = dist[u]+w; if(nwd<dist[v]) { dist[v]=nwd; q.push({-nwd,v}); } } } return dist; } int main() { fio // ifstream cin("in.in"); int n, m, S, T, U, V; cin >> n >> m >> S >> T >> U >> V; while(m--) { int u, v, w; cin >> u >> v >> w; g[u].pb({v,w}); g[v].pb({u,w}); } vector<ll> dS = dijkstra(S,n); vector<ll> dT = dijkstra(T,n); vector<ll> dU = dijkstra(U,n); vector<ll> dV = dijkstra(V,n); ll mincost = dS[T]; for(int i = 1;i<=n;i++) if(dS[i]+dT[i]==mincost) mark[i]=1; ll resU = INF, resV = INF; for(int i = 1;i<=n;i++) { if(mark[i]) { resU = min(resU,dU[i]); resV = min(resV,dV[i]); } } cout << min(dU[V],resU+resV); 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...