이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
#include<queue>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
const int sz=1e5+1;
vector<pair<int,ll>>g[sz];
int s,t,u,v;
int n,m;
ll ans;
ll d0[sz];
ll d1[sz];
ll dx[sz];
ll dpu[sz];
ll dpv[sz];
void dijisktra(int src, ll d[sz]){
using T=pair<ll,int>;
priority_queue<T,vector<T>,greater<T>>pq;
pq.push({0,src});
d[src]=0;
while (pq.size()){
int node;ll val;
tie(val,node)=pq.top();
pq.pop();
if (d[node]!=val) continue;
for(auto u:g[node]){
int p=u.first;
ll dist=u.second+val;
if (dist<d[p]){
pq.push({d[p]=dist,p});
}
}
}
}
ll dpdijisktra(int src){
using T=pair<ll,int>;
priority_queue<T,vector<T>,greater<T>>pq;
dx[src]=0;
pq.push({0,src});
while(pq.size()){
int node;ll val;
tie(val,node)=pq.top();
pq.pop();
if (dx[node]!=val) continue;
for (auto u:g[node]){
int z=u.first;
ll dist=u.second+val;
if (dx[z]==dist){
dpu[z]=min(dpu[z],min(dpu[node],d0[z]));
dpv[z]=min(dpv[z],min(dpu[node],d1[z]));
}
if (dx[z]>dist){
dx[z]=dist;
pq.push({dx[z],z});
dpu[z]=min(dpu[node],d0[z]);
dpv[z]=min(dpv[node],d1[z]);
}
}
} return dpu[t]+dpv[t];
}
int main() {
cin>>n>>m;
cin>>s>>t;
cin>>u>>v;
for (int i=0;i<m;i++){
int x,y; ll t;
cin>>x>>y>>t;
g[x].push_back({y,t});
g[y].push_back({x,t});
} for(int i=1;i<=n;i++){
d1[i]=LLONG_MAX;
d0[i]=LLONG_MAX;
dx[i]=LLONG_MAX;
dpu[i]=LLONG_MAX;
dpv[i]=LLONG_MAX;
}
dijisktra(u,d0);
dijisktra(v,d1);
dpu[u]=0;
dpv[v]=0;
ll res=d0[v];
res=min(dpdijisktra(s),res);
cout <<res;
}
# | 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... |