Submission #47137

#TimeUsernameProblemLanguageResultExecution timeMemory
47137dqhungdlCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
705 ms156224 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int64_t,int64_t> ii; typedef pair<ii,int64_t> iii; int64_t n,m,S,T,U,V,res,d[100005],dS[100005],dT[100005],dU[100005],dV[100005],F1[100005],F2[100005]; bool Free[100005]; vector<int64_t> dag[100005]; vector<ii> g[100005]; vector<iii> Edge; set<ii> s; void Dijkstra(int64_t start) { for(int64_t i=1; i<=n; i++) d[i]=1e15; d[start]=0; s.insert(ii(0,start)); while(s.size()>0) { int64_t u=(*s.begin()).second; s.erase(s.begin()); for(int64_t i=0; i<g[u].size(); i++) { int64_t v=g[u][i].first; int64_t w=g[u][i].second; if(d[v]>d[u]+w) { if(d[v]!=1e15) s.erase(s.find(ii(d[v],v))); d[v]=d[u]+w; s.insert(ii(d[v],v)); } } } } void DFS(int64_t u) { Free[u]=true; F1[u]=dV[u]; F2[u]=dU[u]; for(int64_t i=0; i<dag[u].size(); i++) { int64_t v=dag[u][i]; if(Free[v]==false) DFS(v); F1[u]=min(F1[u],F1[v]); F2[u]=min(F2[u],F2[v]); } res=min(res,min(dU[u]+F1[u],dV[u]+F2[u])); } int main() { ios_base::sync_with_stdio(false); //freopen("TEST.INP","r",stdin); cin>>n>>m>>S>>T>>U>>V; int64_t u,v,w; while(m--) { cin>>u>>v>>w; Edge.push_back(iii(ii(u,v),w)); g[u].push_back(ii(v,w)); g[v].push_back(ii(u,w)); } Dijkstra(S); for(int64_t i=1; i<=n; i++) dS[i]=d[i]; Dijkstra(T); for(int64_t i=1; i<=n; i++) dT[i]=d[i]; Dijkstra(U); for(int64_t i=1; i<=n; i++) dU[i]=d[i]; Dijkstra(V); for(int64_t i=1; i<=n; i++) dV[i]=d[i]; for(int64_t i=0; i<Edge.size(); i++) { int64_t u=Edge[i].first.first; int64_t v=Edge[i].first.second; int64_t w=Edge[i].second; if(dS[u]+dT[v]+w==dS[T]) dag[u].push_back(v); if(dS[v]+dT[u]+w==dS[T]) dag[v].push_back(u); } res=dU[V]; DFS(S); cout<<res; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void Dijkstra(int64_t)':
commuter_pass.cpp:23:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int64_t i=0; i<g[u].size(); i++)
                          ~^~~~~~~~~~~~
commuter_pass.cpp: In function 'void DFS(int64_t)':
commuter_pass.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int64_t i=0; i<dag[u].size(); i++)
                      ~^~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int64_t i=0; i<Edge.size(); i++)
                      ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...