# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
769452 | Alora | Commuter Pass (JOI18_commuter_pass) | C++17 | 267 ms | 32304 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define name "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define int long long
#define f first
#define se second
#define pii pair<ll, int>
#define getbit(i, j) ((i >> j) & 1)
#define pb push_back
#define all(v) v.begin(), v.end()
#define maxn 200005
const int M = 1e9 + 7;
using namespace std;
int n, m, S, T, U, V;
vector <pii> g[maxn];
vector <vector<ll>> dp(5, vector<ll>(maxn, 1e18));
void dij(int x, vector <ll> &L){
L[x] = 0;
priority_queue <pii> q;
q.push({0, x});
while(q.size()){
ll h = -q.top().f;
int u = q.top().se; q.pop();
if(h != L[u]) continue;
for(auto e: g[u]){
int v = e.f, w = e.se;
if(L[v] > L[u] + w){
L[v] = L[u] + w;
q.push({-L[v], v});
}
}
}
}
ll L[maxn], ans = 1e18;
ll sol(int u, ll d, int x){
if(d + dp[1][u] != dp[0][T]) return 1e18;
if(L[u] != -1) return L[u];
ll tmp = dp[5 - x][u];
for(auto e: g[u]){
int v = e.f, w = e.se;
tmp = min(tmp, sol(v, dp[0][u] + w, x));
}
ans = min(ans, dp[x][u] + tmp);
return L[u] = tmp;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//freopen(name".in", "r", stdin);
// freopen(name".out", "w", stdout);
cin >> n >> m;
cin >> S >> T >> U >> V;
fi(i, 1, m){
int u, v, z; cin >> u >> v >> z;
g[u].pb({v, z});
g[v].pb({u, z});
}
dij(S, dp[0]); dij(T, dp[1]);
dij(U, dp[2]); dij(V, dp[3]);
ans = dp[2][V];
fi(i, 1, n) L[i] = -1; sol(S, 0, 2);
fi(i, 1, n) L[i] = -1; sol(S, 0, 3);
cout << ans;
}
Compilation message (stderr)
# | 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... |