Submission #66914

#TimeUsernameProblemLanguageResultExecution timeMemory
66914quoriessCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
2080 ms66988 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef pair<lli,lli> pii; vector<vector<pii> > adj; void dijk(int start,vector<lli>& dist,vector<lli>& pre){ set<pii> nodes; int len=dist.size(); dist=vector<lli>(len,1e17); nodes.insert(pii(0,start)); dist[start]=0; pre=vector<lli>(len,-1); while(!nodes.empty()) { auto sim=*nodes.begin(); nodes.erase(sim); for(auto u:adj[sim.second]){ if(dist[sim.second]+u.second<dist[u.first]){ if(nodes.find(pii(dist[u.first],u.first))!=nodes.end()) nodes.erase(pii(dist[u.first],u.first)); dist[u.first]=dist[sim.second]+u.second; pre[u.first]=sim.second; nodes.insert(pii(dist[u.first],u.first)); } } } } /* 5 7 1 3 1 5 1 2 1 2 3 3 1 3 2 3 4 1 3 5 2 1 4 1 1 5 7 * */ typedef pair<lli,pii> data; lli ans=1e17; void dfs(int node,vector<vector<pii> >& dag,vector<lli>& upminv,vector<lli>& upminu,lli minu,lli minv){ //cout << "sh dag: "<<node<<"\n"; minu=min(upminu[node],minu); minv=min(upminv[node],minv); ans=min(minu+minv,ans); for (auto u:dag[node]) { //cout << node<<"->"<<u.first<<"\n"; dfs(u.first,dag,upminv,upminu,minu,minv); } } int main(){ int n,m; cin>>n>>m; lli s,t,u,v; cin>>s>>t>>u>>v; adj=vector<vector<pii> >(n+1,vector<pii>()); for (int i = 0; i < m; i++) { int a,b,c; cin>>a>>b>>c; adj[a].push_back(pii(b,c)); adj[b].push_back(pii(a,c)); } /* s'den shortest path bul * */ vector<lli> distu(n+1),distv(n+1),preu(n+1),prev(n+1), dists(n+1),pres(n+1),distt(n+1),pret(n+1); dijk(s,dists,pres); dijk(t,distt,pret); vector<vector<pii> > dag(n+1,vector<pii>()),dagters(n+1,vector<pii>()); map<pii,bool> klnm; for(int i=1;i<=n;i++){ for (auto nodi:adj[i]) { if(klnm[pii(nodi.first,i)] || klnm[pii(i,nodi.first)])continue; if(nodi.second+dists[i]+distt[nodi.first]==dists[t]){ dag[i].push_back(pii(nodi.first,nodi.second)); dagters[nodi.first].push_back(pii(i,nodi.second)); } } } dijk(u,distu,preu); dijk(v,distv,prev); vector<lli> upminv(n+1,0),upminu(n+1,0); upminv[s]=distv[s]; upminu[s]=distu[s]; queue<int> nodes; nodes.push(s); bool mark[100006]; while(!nodes.empty()){ int ust=nodes.front(); nodes.pop(); mark[ust]=true; for(auto a: dag[ust]){ upminv[a.first]=min(distv[a.first],upminv[ust]); upminu[a.first]=min(distu[a.first],upminu[ust]); if(!mark[a.first])nodes.push(a.first); } } ans=distv[u]; dfs(s,dag,upminv,upminu,1e16,1e16); cout<<ans<<"\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...