이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
const long long INF = 1e18;
vector<pair<int,int>>g[MX];
int n, m, s, t, u, v;
vector<long long>d(MX, INF), d2(MX, INF), dist(MX, INF), dist2(MX, INF);
vector<long long>dp(MX, INF), dp2(MX, INF);
void PlayGround() {
cin>>n>>m>>s>>t>>u>>v;
for(int i=0; i<m; ++i) {
int a, b, c;
cin>>a>>b>>c;
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
}
for(int sc : {u, v}) {
d[sc] = 0;
priority_queue<pair<long long, int>>pq;
pq.emplace(0, sc);
while(!pq.empty()) {
long long cost;
int node;
tie(cost, node) = pq.top(); pq.pop();
cost = -cost;
if(cost!=d[node]) continue;
for(auto e : g[node]) if(e.second+cost<d[e.first]) {
d[e.first] = cost+e.second;
pq.emplace(-d[e.first], e.first);
}
}
swap(d, d2);
}
for(int sc : {s, t}) {
dist[sc] = 0;
dp[sc] = d2[sc];
priority_queue<pair<long long, int>>pq;
pq.emplace(0, sc);
while(!pq.empty()) {
long long cost; int node;
tie(cost, node) = pq.top(); pq.pop();
cost = -cost;
if(cost!=dist[node]) continue;
for(auto e : g[node]) {
if(e.second+cost<dist[e.first]) {
dist[e.first] = cost+e.second;
dp[e.first] = min(dp[node], d2[e.first]);
pq.emplace(-dist[e.first], e.first);
} else if(e.second+cost==dist[e.first]) {
dp[e.first] = min(dp[e.first], dp[node]);
}
}
}
swap(dp, dp2);
swap(dist, dist2);
}
long long ans = d[v];
for(int i=1; i<=n; ++i) if(dist[i]+dist2[i]==dist[t]) {
ans = min(ans, d[i]+min(dp[i], dp2[i]));
}
cout<<ans<<'\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# | 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... |