이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
vector<pair<int,int>>v[N];
int dist[N];
int tmp[N];
int par[N];
bool vis[N];
vector<pair<int,int>>vc;
void dfs(int a){
vis[a]=1;
for(auto p:v[a]){
int b=p.ff;
int c=p.ss;
if(vis[b]==0 and dist[b]+c==dist[a])dfs(b);
}
}
signed main(){
int n,m,s,t,x,y;
cin>>n>>m>>s>>t>>x>>y;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
v[a].pb({b,c});
v[b].pb({a,c});
}
for(int i=1;i<=n;i++){
dist[i]=1e16;
}
priority_queue<pair<int,int>>q;
q.push({0,s});
par[s]=s;
dist[s]=0;
vis[s]=1;
while(!q.empty()){
int w=-q.top().ff;
int a=q.top().ss;
q.pop();
if(dist[a]<w)continue;
for(auto p:v[a]){
int b=p.ff;
int c=p.ss;
if(dist[a]+c<dist[b]){
dist[b]=dist[a]+c;
par[b]=a;
q.push({-dist[b],b});
}
}
}
dfs(t);
for(int i=1;i<=n;i++){
dist[i]=1e16;
}
s=y;
q.push({0,s});
dist[s]=0;
while(!q.empty()){
int w=-q.top().ff;
int a=q.top().ss;
q.pop();
if(dist[a]<w)continue;
for(auto p:v[a]){
int b=p.ff;
int c=p.ss;
if(dist[a]+c<dist[b]){
dist[b]=dist[a]+c;
par[b]=a;
q.push({-dist[b],b});
}
}
}
int ans=INT_MAX;
for(int i=1;i<=n;i++){
if(vis[i]){
ans=min(ans,dist[i]);
}
}
cout<<ans;
}
# | 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... |