제출 #487098

#제출 시각아이디문제언어결과실행 시간메모리
487098PoPularPlusPlusCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
262 ms24424 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const int mod = 1000000007; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; bool remender(ll a , ll b){return a%b;} const int N = 100002; vector<pair<int,ll>> adj[N]; ll dis[N]; void mem(){ for(int i = 0; i < N; i++)dis[i] = 1e18; } void Dijkstra(ll e){ priority_queue< pair<ll,ll>, vector <pair<ll,ll>> , greater<pair<ll,ll>> > pq; dis[e]=0; pq.push({0,e}); while(!pq.empty()){ ll node = pq.top().second,ww=pq.top().first; pq.pop(); if(dis[node] < ww)continue; for(auto i : adj[node]){ ll w = i.second; if(dis[i.first] > dis[node] + w){ dis[i.first] = dis[node] + w; pq.push({dis[i.first],i.first}); } } } } void solve(){ int n , m; cin >> n >> m; int s , t; cin >> s >> t; int a , b; cin >> a >> b; for(int i = 0; i < m; i++){ ll x , y , z; cin >> x >> y >> z; adj[x].pb(mp(y,z)); adj[y].pb(mp(x,z)); } ll dis1[N] , dis2[N]; mem(); Dijkstra(a); for(int i = 0; i <= n; i++)dis1[i] = dis[i]; mem(); Dijkstra(b); for(int i = 0; i <= n; i++)dis2[i] = dis[i]; mem(); Dijkstra(s); ll mn[N] , mx[N]; for(int i = 0; i <= n; i++)mn[i] = dis1[i]; for(int i = 0; i <= n; i++)mx[i] = dis2[i]; queue<int> q; bool vis[N]; memset(vis,0,sizeof vis); vis[t] = 1; q.push(t); int cnt[N]; memset(cnt,0,sizeof cnt); while(q.size()){ int node = q.front(); q.pop(); for(auto i : adj[node]){ if(dis[i.vf] + i.vs == dis[node]){ cnt[i.vf]++; if(!vis[i.vf]){ vis[i.vf] = 1; q.push(i.vf); } } } } ll ans = dis1[b]; q.push(t); while(q.size()){ int node = q.front(); q.pop(); ans = min(ans , min(dis1[node] + mx[node] , dis2[node] + mn[node])); for(auto i : adj[node]){ if(dis[i.vf] == dis[node] - i.vs){ mn[i.vf] = min(mn[i.vf] , mn[node]); mx[i.vf] = min(mx[i.vf] , mx[node]); cnt[i.vf]--; if(cnt[i.vf] == 0){ q.push(i.vf); } } } } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //int t;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...