제출 #1167641

#제출 시각아이디문제언어결과실행 시간메모리
1167641lizaCommuter Pass (JOI18_commuter_pass)C++20
16 / 100
274 ms18044 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target ("avx2,bmi,bmi2,popcnt,lzcnt") using namespace std; const int N = 100005; vector<pair<int, long long>> graph[N]; long long dv[N], dt[N], ds[N], du[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for(int i = 0; i < m; i++) { int a, b; long long c; cin >> a >> b >> c; graph[a].push_back({b, c}); graph[b].push_back({a, c}); } priority_queue <pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq; for(int i = 0; i <= n; i++)ds[i]= 1e18; int vis[N]={0}; ds[s]=0; pq.push({0, s}); while(!pq.empty()) { pair<long long,int> x = pq.top(); pq.pop(); if(vis[x.second]==1)continue; vis[x.second]=1; for(auto i: graph[x.second]) { if(ds[i.first] > x.first+i.second) { pq.push({x.first+i.second, i.first}); ds[i.first]=x.first+i.second; } } } for(int i = 0; i <= n; i++) { dt[i]= 1e18; vis[i]=0; } dt[t]=0; pq.push({0, t}); while(!pq.empty()) { pair<long long,int> x = pq.top(); pq.pop(); if(vis[x.second]==1)continue; vis[x.second]=1; for(auto i: graph[x.second]) { if(dt[i.first] > x.first+i.second) { pq.push({x.first+i.second, i.first}); dt[i.first]=x.first+i.second; } } } for(int i = 0; i <= n; i++) { dv[i]= 1e18; vis[i]=0; } dv[v]=0; pq.push({0, v}); while(!pq.empty()) { pair<long long,int> x = pq.top(); pq.pop(); if(vis[x.second]==1)continue; vis[x.second]=1; for(auto i: graph[x.second]) { if(dv[i.first] > x.first+i.second) { pq.push({x.first+i.second, i.first}); dv[i.first]=x.first+i.second; } } } for(int i = 0; i <= n; i++) { du[i]= 1e18; vis[i]=0; } du[u]=0; pq.push({0, u}); while(!pq.empty()) { pair<long long,int> x = pq.top(); pq.pop(); if(vis[x.second]==1)continue; vis[x.second]=1; for(auto i: graph[x.second]) { if(du[i.first] > x.first+i.second) { pq.push({x.first+i.second, i.first}); du[i.first]=x.first+i.second; } } } long long rezu=1e18, rezv= 1e18; for(int i = 1; i <= n; i++) { if(dv[i] < rezv) { if(dt[i]+ds[i]==ds[t]) { rezv=dv[i]; } } if(du[i] < rezu) { if(dt[i]+ds[i]==ds[t]) { rezu=du[i]; } } } cout << rezv +rezu << "\n"; 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...