Submission #82478

#TimeUsernameProblemLanguageResultExecution timeMemory
82478rafataCommuter Pass (JOI18_commuter_pass)C++14
24 / 100
88 ms4428 KiB
#include <bits/stdc++.h> using namespace std; const long long oo=1e18; const int N=500; long long c[N][N]; int n,m,a,b,s,t; int main() { //freopen("i.inp","r",stdin); cin>>n>>m>>a>>b>>s>>t; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) c[i][j]=oo; for(int i=1;i<=m;i++) { long long u,v,w; cin>>u>>v>>w; c[u][v]=c[v][u]=min(c[u][v],w); } for(int k=1;k<=n;k++) for(int u=1;u<=n;u++) for(int v=1;v<=n;v++) if(c[u][k] && c[k][v]) c[u][v]=min(c[u][v],c[u][k]+c[k][v]); long long ans=c[s][t]; for(int x=1;x<=n;x++) for(int y=1;y<=n;y++) if(c[a][x] + c[x][y]+ c[y][b] ==c[a][b]) ans=min(ans,c[x][s]+c[y][t]); swap(a,b); for(int x=1;x<=n;x++) for(int y=1;y<=n;y++) if(c[a][x] + c[x][y]+ c[y][b] ==c[a][b]) ans=min(ans,c[x][s]+c[y][t]); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...