Submission #649868

#TimeUsernameProblemLanguageResultExecution timeMemory
649868UzoufCommuter Pass (JOI18_commuter_pass)C++14
24 / 100
141 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; int s,t,u,v; cin>>s>>t>>u>>v; vector<vector<pair<int,int> > > vv(n+5); int fl1[n+5][n+5],fl2[n+5][n+5]; for (int i=0;i<=n;i++) { for (int j=0;j<=n;j++) { fl1[i][j]=1e18; fl2[i][j]=1e18; } fl1[i][i]=0; fl2[i][i]=0; } for (int i=0;i<m;i++) { int a,b,c; cin>>a>>b>>c; vv[a].push_back({b,c}); vv[b].push_back({a,c}); fl1[a][b]=c; fl1[b][a]=c; fl2[a][b]=c; fl2[b][a]=c; } int diss[n+5],dist[n+5],disv[n+5],disu[n+5],par[n+5]; for (int i=0;i<=n;i++) { diss[i]=dist[i]=disv[i]=disu[i]=1e18; par[i]=-1; } /*priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q; q.push({0,s}); diss[s]=0; par[s]=s; while (!q.empty()) { int c=q.top().first,i=q.top().second; q.pop(); if (c>diss[i]) continue; for (int j=0;j<vv[i].size();j++) { int ii=vv[i][j].first,cc=vv[i][j].second; int nwc=c+cc; if (diss[ii]>nwc) { diss[ii]=nwc; q.push({nwc,ii}); par[ii]=i; } } } q.push({0,t}); dist[t]=0; while (!q.empty()) { int c=q.top().first,i=q.top().second; q.pop(); if (c>dist[i]) continue; for (int j=0;j<vv[i].size();j++) { int ii=vv[i][j].first,cc=vv[i][j].second; int nwc=c+cc; if (dist[ii]>nwc) { dist[ii]=nwc; q.push({nwc,ii}); } } } int indx=t; while (indx!=s) { for (int i=0;i<vv[indx].size();i++) { if (vv[indx][i].first==par[indx]) vv[indx][i].second=0; } for (int i=0;i<vv[par[indx]].size();i++) { if (vv[par[indx]][i].first==indx) vv[par[indx]][i].second=0; } fl2[indx][par[indx]]=0; fl2[par[indx]][indx]=0; indx=par[indx]; } q.push({0,v}); disv[v]=0; while (!q.empty()) { int c=q.top().first,i=q.top().second; q.pop(); if (c>disv[i]) continue; for (int j=0;j<vv[i].size();j++) { int ii=vv[i][j].first,cc=vv[i][j].second; int nwc=c+cc; if (disv[ii]>nwc) { disv[ii]=nwc; q.push({nwc,ii}); } } } q.push({0,u}); disu[u]=0; while (!q.empty()) { int c=q.top().first,i=q.top().second; q.pop(); if (c>disu[i]) continue; for (int j=0;j<vv[i].size();j++) { int ii=vv[i][j].first,cc=vv[i][j].second; int nwc=c+cc; if (disu[ii]>nwc) { disu[ii]=nwc; q.push({nwc,ii}); } } } if (s!=u) { cout<<disv[u]; return 0; } //-------------------------------------- int ans=1e18; for (int i=1;i<=n;i++) { if (diss[i]+dist[i]==diss[t]) { ans=min(ans,disv[i]); } } if (n>300) { cout<<ans; return 0; }*/ //--------------------------------------- for(int k=1;k<=n;k++) { for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { fl1[i][j]=min(fl1[i][j],fl1[i][k]+fl1[k][j]); fl2[i][j]=min(fl2[i][j],fl2[i][k]+fl2[k][j]); } } } int ans=fl1[u][v]; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { if (fl1[s][i]+fl1[i][j]+fl1[j][t]==fl1[s][t] || fl1[s][j]+fl1[j][i]+fl1[i][t]==fl1[s][t]) { ans=min({ans,fl1[u][i]+fl1[j][v],fl1[u][j]+fl1[i][v]}); } } } cout<<ans; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:28:9: warning: variable 'diss' set but not used [-Wunused-but-set-variable]
   28 |     int diss[n+5],dist[n+5],disv[n+5],disu[n+5],par[n+5];
      |         ^~~~
commuter_pass.cpp:28:49: warning: variable 'par' set but not used [-Wunused-but-set-variable]
   28 |     int diss[n+5],dist[n+5],disv[n+5],disu[n+5],par[n+5];
      |                                                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...