이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
const int maxn=1e5;
int n,m;
vector<pll> adj[maxn+1];
ll ds[maxn+1],dx[maxn+1],dy[maxn+1],dp1[maxn+1],dp2[maxn+1],ans=1e18;
void dj(int v,ll dist[]){
for(int i=1;i<=n;i++)dist[i]=1e18;
bool vis[n+1];
memset(vis,0,sizeof(vis));
priority_queue<pll> pq;
dist[v]=0;
pq.push({0,v});
while(!pq.empty()){
ll i=pq.top().sc;
pq.pop();
if(vis[i])continue;
vis[i]=1;
for(auto[u,w]:adj[i])if(!vis[u]){
dist[u]=min(dist[u],dist[i]+w);
pq.push({-dist[u],u});
}
}
}
ll f1(int v){
if(dp1[v]!=-1)return dp1[v];
ll x=dy[v];
for(auto[u,w]:adj[v]){
if(ds[v]==ds[u]+w){
ll y=f1(u);
x=min(x,y);
ans=min(ans,dx[v]+y);
}
}
return dp1[v]=x;
}
ll f2(int v){
if(dp2[v]!=-1)return dp2[v];
ll x=dx[v];
for(auto[u,w]:adj[v]){
if(ds[v]==ds[u]+w){
ll y=f2(u);
x=min(x,y);
ans=min(ans,dy[v]+y);
}
}
return dp2[v]=x;
}
void solve() {
cin>>n>>m;
int s,t,x,y;
cin>>s>>t>>x>>y;
while(m--){
int u,v,w;
cin>>u>>v>>w;
adj[u].pb({v,w});
adj[v].pb({u,w});
}
dj(s,ds);
dj(x,dx);
dj(y,dy);
memset(dp1,-1,sizeof(dp1));
f1(t);
memset(dp2,-1,sizeof(dp2));
f2(t);
cout<<min(ans,dx[y]);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# | 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... |