제출 #1167602

#제출 시각아이디문제언어결과실행 시간메모리
1167602mareksbCommuter Pass (JOI18_commuter_pass)C++20
31 / 100
204 ms19512 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3,unroll-loops") #pragma GCC target ("avx2,bmi,bmi2,popcnt,lzcnt") using namespace std; const int64_t N=100005; vector<pair<int64_t,int64_t>> mas[N]; int64_t dS[N]; int64_t dT[N]; int64_t dV[N]; int64_t dU[N]; int64_t n,m; int64_t s,t;//commuter pass int64_t u,v; void dijkstra(int64_t start, int64_t* dist){ priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>> pq; dist[start]=0; pq.push({0,start}); while(!pq.empty()){ int64_t x=pq.top().second; pq.pop(); for(auto p:mas[x]){ if(dist[x]+p.second<dist[p.first]){ dist[p.first]=dist[x]+p.second; pq.push({dist[p.first],p.first}); } } } } void dijkstra2(int64_t start, int64_t* dist){ priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>> pq; dist[start]=0; pq.push({0,start}); while(!pq.empty()){ int64_t x=pq.top().second; pq.pop(); for(auto p:mas[x]){ int64_t cost=p.second; if(dS[x]+dT[x]==dS[t]&&dS[p.first]+dT[p.first]==dS[t]){ cost=0; } if(dist[x]+cost<dist[p.first]){ dist[p.first]=dist[x]+cost; pq.push({dist[p.first],p.first}); } } } } void solve(){ cin>>n>>m; for(int64_t i=0;i<=n;i++){ dS[i]=LLONG_MAX/4; dT[i]=LLONG_MAX/4; dV[i]=LLONG_MAX/4; dU[i]=LLONG_MAX/4; } cin>>s>>t; cin>>u>>v; for(int64_t i=0;i<m;i++){ int64_t x,y,c; cin>>x>>y>>c; mas[x].push_back({y,c}); mas[y].push_back({x,c}); } dijkstra(s,dS); dijkstra(t,dT); dijkstra2(v,dV); dijkstra2(u,dU); cout<<dV[u]<<'\n'; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int64_t t=1; //cin>>t; while(t--){ 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...