제출 #1167640

#제출 시각아이디문제언어결과실행 시간메모리
1167640lizaCommuter Pass (JOI18_commuter_pass)C++20
16 / 100
234 ms17952 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]; 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; } } } /* int du[100005]={0}; du[u]=0; priv = u; pq.push({0, u}); while(pq.size()) { pair<int,int> x = pq.top(); pq.pop(); for(auto i: graph[x.second]) { if(i.first==priv)continue; if(du[i.first]==0 || du[i.first] > x.first+i.second) { pq.push({x.first+i.second, i.first}); du[i.first]=x.first+i.second; } } priv=x.second; } */ long long rezv= 1e18; for(int i = 1; i <= n; i++) { if(dv[i] < rezv) { if(dt[i]+ds[i]==ds[t]) { rezv=dv[i]; } } } cout << rezv << "\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...