이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e14 + 10000;
const int mod = 1e9+7;
const int maxn = 5e5 + 12;
vt<pii> g[maxn];
void ope(vll &a, int st){
a[st] = 0;
priority_queue<pair<ll, int>, vt<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({0, st});
while(!pq.empty()){
pair<ll, int> nw = pq.top();
pq.pop();
if(a[nw.ss] != nw.ff)continue;
for(auto i : g[nw.ss]){
if(nw.ff + i.ss < a[i.ff]) {
a[i.ff] = nw.ff + i.ss;
pq.push({a[i.ff], i.ff});
}
}
}
}
void solve() {
int n, m, s, t, u, v;
cin >> n >> m >> s >> t >> u >> v;
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
g[a].pb({b, c});
g[b].pb({a, c});
}
s--, t--, u--, v--;
vll a(n, inf), b(n, inf), c(n, inf), d(n, inf);
ope(a, s), ope(b, t), ope(c, u), ope(d, v);
queue<tuple<int, ll, ll>> q;
q.push({t, c[t], d[t]});
ll ans = d[u];
while(!q.empty()){
tuple<int, ll, ll> nw = q.front();
ans = min(ans, get<1>(nw) + get<2>(nw));
q.pop();
for(auto i : g[get<0>(nw)]){
if(a[i.ff] + i.ss == a[get<0>(nw)]){
q.push({i.ff, min(get<1>(nw), c[i.ff]), min(get<2>(nw), d[i.ff])});
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
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... |