이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
const int nax=1e5+5;
vector<pair<int,ll> > grafo[nax];
vector<int> dag[nax];
ll dists[nax],distv[nax],distu[nax];
ll dpu[nax],dpv[nax];
bitset<nax> v;
priority_queue<pair<ll,int> > q;
void dfs(int n){
if(v[n])return;
v[n]=1;
for(auto x:grafo[n])
if(dists[n]+x.s==dists[x.f]){
dag[x.f].push_back(n);
dfs(x.f);
}
}
void dijkstra(ll* d, int s, int n){
for(int i=0;i<=n;i++)d[i]=LLONG_MAX;
d[s]=0;
q.emplace(0,s);
while(!q.empty()){
int co=q.top().s;
q.pop();
for(auto x:grafo[co])
if(d[co]+x.s<d[x.f]){
d[x.f]=d[co]+x.s;
q.emplace(-d[x.f],x.f);
}
}
}
ll ricu(int n, int s){
if(n==s)return distu[s];
if(dpu[n]!=1e15)return dpu[n];
dpu[n]=distu[n];
for(int x:dag[n]){
dpu[n]=min(dpu[n],ricu(x,s));
}
return dpu[n];
}
ll ricv(int n, int s){
if(n==s)return distv[s];
if(dpv[n]!=1e15)return dpv[n];
dpv[n]=distv[n];
for(int x:dag[n]){
dpv[n]=min(dpv[n],ricv(x,s));
}
return dpv[n];
}
int main(){
int n,m,s,t,u,v;
cin>>n>>m>>s>>t>>u>>v;
t--,u--,v--,s--;
for(int i=0;i<m;i++){
ll a,b,c;
cin>>a>>b>>c;
a--,b--;
grafo[a].emplace_back(b,c);
grafo[b].emplace_back(a,c);
}
dijkstra(dists,s,n);
dijkstra(distv,v,n);
dijkstra(distu,u,n);
dfs(s);
for(int i=0;i<=n;i++)dpu[i]=1e15;
for(int i=0;i<=n;i++)dpv[i]=1e15;
ricu(t,s);
ricv(t,s);
ll sol=LLONG_MAX;
for(int i=0;i<n;i++)if(dpv[i]!=-1)sol=min(sol,dpu[i]+dpv[i]);
cout<<sol<<endl;
}
# | 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... |