# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879209 | mahmoudbadawy | Commuter Pass (JOI18_commuter_pass) | C++17 | 321 ms | 19284 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m;
vector< pair<int,int> > adj[N];
long long dis[4][N];
int sp[4];
void calc(int ind)
{
for(int i=1;i<=n;i++) dis[ind][i]=(1LL<<60);
int x=sp[ind];
dis[ind][x]=0;
set<pair<long long,int> > ss;
ss.insert({0,x});
while(ss.size())
{
int u=(*ss.begin()).second;
ss.erase(ss.begin());
for(auto i:adj[u])
{
int v=i.first, c=i.second;
if(dis[ind][u]+c < dis[ind][v])
{
if(dis[ind][v]!=(1LL<<60)) ss.erase({dis[ind][v],v});
dis[ind][v]=dis[ind][u]+c;
ss.insert({dis[ind][v],v});
}
}
}
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=0;i<4;i++) scanf("%d",&sp[i]);
for(int i=0;i<m;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
adj[x].push_back({y,z});
adj[y].push_back({x,z});
}
for(int i=0;i<4;i++) calc(i);
long long a=(1LL<<60), b=(1LL<<60);
for(int i=1;i<=n;i++)
{
if(dis[0][i]+dis[1][i]==dis[0][sp[1]]) // (S to i) + (i to T) = (S to T)
{
a=min(a, dis[2][i]); // U to i
b=min(b, dis[3][i]); // i to V
}
}
//cout << a << " " << b << endl;
printf("%lld\n", min(a+b, dis[2][sp[3]]));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |