이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// PhuThuyRuntime <3
// A secret makes a woman woman
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fo(i, l, r) for(int i = l; i <= r; i++)
#define foi(i, l, r) for(int i = l; i >= r; i--)
#define elif else if
#define el cout << "\n";
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define fi first
#define se second
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define ll long long
#define ull unsigned long long
#define pob pop_back
#define bs binary_search
#define vi vector<int>
#define vii vector<pair<int, int>>
#define getbit(i, j) (i >> j) & 1
#define offbit(i, j) (1 << j) ^ i
#define onbit(i, j) (1 << j) | i
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
const int inf = INT_MAX;
const int base = 31;
const long double EPS = 1e-9;
const long double pi = acos(-1.0);
int n, m, s, t, pd, tr;
vii adj[N];
void inp(){
cin >> n >> m >> s >> t >> pd >> tr;
fo(i, 1, m){
int u, v, c;
cin >> u >> v >> c;
adj[u].emplace_back(v, c);
adj[v].emplace_back(u, c);
}
}
ll du[N], dv[N];
void dij(int s, ll d[]){
d[s] = 0;
priority_queue<pli, vector<pli>, greater<pli>> q;
q.push({0, s});
while(!q.empty()){
int u = q.top().se;
ll val = q.top().fi;
q.pop();
if(d[u] != val) continue;
for(auto it : adj[u]){
int v = it.fi, c = it.se;
if(d[v] > d[u] + c){
d[v] = d[u] + c;
q.push({d[v], v});
}
}
}
}
ll dsu[N], dsv[N];
void dij(int s, ll d[], int t){
d[s] = 0;
priority_queue<pli, vector<pli>, greater<pli>> q;
q.push({0, s});
while(!q.empty()){
int u = q.top().se;
ll val = q.top().fi;
q.pop();
if(d[u] != val) continue;
for(auto [v, c] : adj[u]){
if(d[v] > d[u] + c){
d[v] = d[u] + c;
q.push({d[v], v});
}
if(d[v] >= d[u] + c){
dsu[v] = min(dsu[v], dsu[u]);
dsv[v] = min(dsv[v], dsv[u]);
}
}
}
}
ll d[N];
void sol(){
memset(du, 0x3f, sizeof(du));
memset(dv, 0x3f, sizeof(dv));
memset(d, 0x3f, sizeof(d));
dij(pd, du);
dij(tr, dv);
fo(i, 1, n) dsu[i] = du[i];
fo(i, 1, n) dsv[i] = dv[i];
ll ans = du[tr];
dij(s, d, t);
// cout << ans, el
ans = min(ans, dsu[t] + dsv[t]);
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
inp();
sol();
return 0;
}
/*
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
*/
# | 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... |