이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 998244353
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,s,t,u,v,du[100005],dv[100005],ds[100005],dp[2][100005],ans;
map<ll,ll>viz;
vector<pair<ll,ll>>g[500005];
void d1(ll start,ll a[]){
viz.clear();
priority_queue<pair<ll,ll>>q;
q.push(mp(0,start));
while(!q.empty()){
pair<ll,ll>p=q.top();
q.pop();
if(viz[p.s]==0){
a[p.s]=-p.f;
viz[p.s]=1;
for(auto it : g[p.s]){
q.push(mp(p.f-it.s,it.f));
}
}
}
}
void d2(ll start,ll endd){
fill(dp[0],dp[0]+100001,INF);
fill(dp[1],dp[1]+100001,INF);
viz.clear();
priority_queue<pair<ll,pair<ll,ll>>>q;
q.push(mp(0,mp(start,0)));
dp[0][0]=dp[1][0]=INF;
while(!q.empty()){
ll node,c,par;
node=q.top().s.f;
c=q.top().f;
par=q.top().s.s;
q.pop();
if(viz[node]==0){
viz[node]=1;
ds[node]=-c;
dp[0][node]=min(du[node],dp[0][par]);
dp[1][node]=min(dv[node],dp[1][par]);
for(auto it : g[node]){
q.push(mp(c-it.s,mp(it.f,node)));
}
}else if(-c==ds[node]){
if(min(du[node],dp[0][par])+min(dv[node],dp[1][par])<=dp[0][node]+dp[1][node]){
dp[0][node]=min(du[node],dp[0][par]);
dp[1][node]=min(dv[node],dp[1][par]);
}
}
}
ans=min(ans,dp[0][endd]+dp[1][start]);
}
int32_t main(){
CODE_START;
cin>>n>>m>>s>>t>>u>>v;
for(ll i=0;i<m;i++)
{
ll x,y,z;
cin>>x>>y>>z;
g[x].pb(mp(y,z));
g[y].pb(mp(x,z));
}
d1(u,du);
d1(v,dv);
ans=du[v];
d2(s,t);
d2(t,s);
cout<<ans<<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... |