Submission #983627

#TimeUsernameProblemLanguageResultExecution timeMemory
983627dpsaveslivesCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
285 ms36828 KiB
#include <bits/stdc++.h> #define f first #define s second #define ll long long using namespace std; const int MAXN = 1e5+10; const ll INF = 1e18; vector<pair<int,ll>> adj[MAXN],adj2[MAXN],readj[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N,M; cin >> N >> M; int S,T; cin >> S >> T; int U,V; cin >> U >> V; for(int i = 0;i<M;++i){ int a,b,c; cin >> a >> b >> c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } vector<ll> DU(N+1,INF); DU[U] = 0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; pq.push({0,U}); while(!pq.empty()){ int u = pq.top().s; ll d = pq.top().f; pq.pop(); if(d != DU[u]) continue; for(auto p : adj[u]){ if(p.s+d < DU[p.f]){ DU[p.f] = p.s+d; pq.push({DU[p.f],p.f}); } } } vector<ll> DV(N+1,INF); DV[V] = 0; pq.push({0,V}); while(!pq.empty()){ int u = pq.top().s; ll d = pq.top().f; pq.pop(); if(d != DV[u]) continue; for(auto p : adj[u]){ if(p.s+d < DV[p.f]){ DV[p.f] = p.s+d; pq.push({DV[p.f],p.f}); } } } vector<ll> DS(N+1,INF); DS[S] = 0; pq.push({0,S}); while(!pq.empty()){ int u = pq.top().s; ll d = pq.top().f; pq.pop(); if(d != DS[u]) continue; for(auto p : adj[u]){ if(p.s+d < DS[p.f]){ DS[p.f] = p.s+d; pq.push({DS[p.f],p.f}); } } } vector<ll> DT(N+1,INF); DT[T] = 0; pq.push({0,T}); while(!pq.empty()){ int u = pq.top().s; ll d = pq.top().f; pq.pop(); if(d != DT[u]) continue; for(auto p : adj[u]){ if(p.s+d < DT[p.f]){ DT[p.f] = p.s+d; pq.push({DT[p.f],p.f}); } } } vector<int> indeg(N+1,0); for(int i = 1;i<=N;++i){ if(DT[i]+DS[i] != DS[T]) continue; for(auto p : adj[i]){ if(DT[p.f]+DS[p.f] != DS[T]) continue; if(DS[i]+p.s == DS[p.f]){ adj2[i].push_back({p.f,p.s}); readj[p.f].push_back({i,p.s}); } } } queue<int> q; q.push(S); vector<ll> dp(N+1,INF); for(int i = 1;i<=N;++i){ dp[i] = DU[i]; } ll ans = DU[V]; vector<ll> cnt(N+1,0); while(!q.empty()){ int u = q.front(); q.pop(); ans = min(ans,dp[u]+DV[u]); for(auto p : adj2[u]){ dp[p.f] = min(dp[p.f],dp[u]); ++cnt[p.f]; if(cnt[p.f] == readj[p.f].size()){ q.push(p.f); } } } q.push(T); dp = vector<ll>(N+1,INF); cnt = vector<ll>(N+1,0); for(int i = 1;i<=N;++i){ dp[i] = DU[i]; } while(!q.empty()){ int u = q.front(); q.pop(); ans = min(ans,dp[u]+DV[u]); for(auto p : readj[u]){ dp[p.f] = min(dp[p.f],dp[u]); ++cnt[p.f]; if(cnt[p.f] == adj2[p.f].size()){ q.push(p.f); } } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:88:25: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |             if(cnt[p.f] == readj[p.f].size()){
commuter_pass.cpp:104:25: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |             if(cnt[p.f] == adj2[p.f].size()){
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...