이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<queue>
#include<tuple>
#include<algorithm>
#include<climits>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<long long, long long>
#define INF LLONG_MAX/2
ll n,m,s,t,u,v,ans;
vector<pii> con[100005];
ll du[100005];
ll dv[100005];
void dijkstra(ll src, ll dist[])
{
for(int i=0;i<=n;i++)
dist[i]=INF;
dist[src]=0;
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0,src});
ll cdist,nod,adj,w;
while(!pq.empty())
{
tie(cdist,nod)=pq.top();
pq.pop();
if(cdist!=dist[nod])
continue;
for(auto aux:con[nod])
{
tie(adj,w)=aux;
if(dist[adj]>dist[nod]+w)
{
dist[adj]=dist[nod]+w;
pq.push({dist[adj],adj});
}
}
}
}
ll dpu[100005];
ll dpv[100005];
ll dst[100005];
void dijkstra_parent(ll src, ll ult)
{
for(int i=0;i<=n;i++)
dpu[i]=dpv[i]=dst[i]=INF;
priority_queue<pii,vector<pii>,greater<pii>> pq;
pq.push({0,src});
dst[src]=0;
dpu[src]=du[src];
dpv[src]=dv[src];
ll cdist,nod,adj,w;
while(!pq.empty())
{
tie(cdist,nod)=pq.top();
pq.pop();
if(cdist!=dst[nod])
continue;
for(auto aux:con[nod])
{
tie(adj,w)=aux;
if(dst[adj]>dst[nod]+w)
{
dst[adj]=dst[nod]+w;
dpu[adj]=min(du[adj], dpu[nod]);
dpv[adj]=min(dv[adj], dpv[nod]);
pq.push({dst[adj],adj});
}
else if(dst[adj]==dst[nod]+w && min(du[adj], dpu[nod])+min(dv[adj], dpv[nod])<dpu[adj]+dpv[adj])
{
dpu[adj]=min(du[adj], dpu[nod]);
dpv[adj]=min(dv[adj], dpv[nod]);
}
}
}
ans=min(ans,dpu[ult]+dpv[ult]);
}
int main()
{
ll a,b,c;
cin>>n>>m>>s>>t>>u>>v;
for(ll i=1;i<=m;i++)
{
cin>>a>>b>>c;
con[a].pb({b,c});
con[b].pb({a,c});
}
dijkstra(u,du);
dijkstra(v,dv);
ans=du[v];
dijkstra_parent(s,t);
dijkstra_parent(t,s);
cout<<ans<<"\n";
}
# | 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... |