이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define int long long
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 200005;
int n, m;
int S, T, U, V;
vector<pii> G[MX];
void nhap(){
cin >> n >> m;
cin >> S >> T >> U >> V;
for(int i=1; i<=m; i++){
int u, v, c;
cin >> u >> v >> c;
G[u].push_back({v, c});
G[v].push_back({u, c});
}
}
void dijkstra(int u, int *d){
for(int i=1; i<=n; i++) d[i] = 1e18;
priority_queue<pii> Q;
Q.push({0, u});
d[u] = 0;
while(Q.size()){
int du, u;
tie(du, u) = Q.top();
du = -du;
Q.pop();
if(du != d[u]) continue;
for(pii &tmp: G[u]){
int v, c; tie(v, c) = tmp;
c += du;
if(c < d[v]){
d[v] = c;
Q.push({-c, v});
}
}
}
}
int dS[MX], dT[MX], dU[MX], dV[MX];
int f1[MX], f2[MX];
void solve(){
dijkstra(S, dS);
dijkstra(T, dT);
dijkstra(U, dU);
dijkstra(V, dV);
int ans = dU[V];
vector<int> vt(n);
for(int i=1; i<=n; i++) vt[i-1] = i;
function<bool(const int &, const int &)> comp = [&](const int &a, const int &b){
return dS[a] < dS[b];
};
sort(vt.begin(), vt.end(), comp);
for(int u: vt) if(dS[u] + dT[u] == dS[T]){
f1[u] = dU[u];
f2[u] = dV[u];
for(pii tmp: G[u]){
int v, c; tie(v, c) = tmp;
if(dS[v] + c == dS[u]){
f1[u] = min(f1[u], f1[v]);
f2[u] = min(f2[u], f2[v]);
}
}
ans = min({ans, f1[u] + dV[u], f2[u] + dU[u]});
}
cout << ans;
}
int32_t main(){
fastIO;
//freopen("xebuyt.inp","r",stdin);
//freopen("xebuyt.out","w",stdout);
nhap();
solve();
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... |