Submission #245099

#TimeUsernameProblemLanguageResultExecution timeMemory
245099uacoder123Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
846 ms28668 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef long long int lli; typedef pair <lli,lli> ii; typedef pair <lli,ii> iii; typedef vector <lli> vi; vector<ii> al[100001]; lli dis[100001][4]; int vis[100001]={}; lli ans,t; iii arr[100001]; void dij(lli so,lli ty) { set<ii>s; s.insert(mp(0*1ll,so)); while(s.size()!=0) { ii v=(*s.begin()); s.erase(s.begin()); dis[v.S][ty]=v.F; for(lli i=0;i<al[v.S].size();++i) { if(dis[al[v.S][i].F][ty]==-1 or dis[al[v.S][i].F][ty]>v.F+al[v.S][i].S) { s.erase(mp(dis[al[v.S][i].F][ty],al[v.S][i].F)); dis[al[v.S][i].F][ty]=al[v.S][i].S+v.F; s.insert(mp(dis[al[v.S][i].F][ty],al[v.S][i].F)); } } } } void dfs(int s) { vis[s]=1; if(s==t) { arr[t]=mp(dis[t][2]+dis[t][3],mp(dis[t][2],dis[t][3])); return; } for(int i=0;i<al[s].size();++i) { if(dis[s][0]+al[s][i].S+dis[al[s][i].F][1]!=dis[t][0]) continue; if(!vis[al[s][i].F]) dfs(al[s][i].F); arr[s].S.F=min(arr[s].S.F,min(arr[al[s][i].F].S.F,dis[s][2])); arr[s].S.S=min(arr[s].S.S,min(arr[al[s][i].F].S.S,dis[s][3])); arr[s].F=min(arr[s].F,min(arr[al[s][i].F].F,min(dis[s][2]+dis[s][3],min(dis[s][2]+arr[al[s][i].F].S.S,dis[s][3]+arr[al[s][i].F].S.F)))); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli test=1; for(;test>0;--test) { lli n,m,s,u,v; cin>>n>>m>>s>>t>>u>>v; for(lli i=0;i<m;++i) { lli f,s,w; cin>>f>>s>>w; al[f].pb(mp(s,w)); al[s].pb(mp(f,w)); } memset(dis,-1,sizeof(dis)); dij(s,0); dij(t,1); dij(u,2); dij(v,3); for(int i=0;i<=n;++i) arr[i]=mp(1000000000000000000,mp(1000000000000000000,1000000000000000000)); dfs(s); ans=dis[v][2]; cout<<min(ans,arr[s].F)<<endl; } return(0); }

Compilation message (stderr)

commuter_pass.cpp: In function 'void dij(lli, lli)':
commuter_pass.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(lli i=0;i<al[v.S].size();++i)
                 ~^~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'void dfs(int)':
commuter_pass.cpp:50:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<al[s].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...