# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170581 | ZwariowanyMarcin | Commuter Pass (JOI18_commuter_pass) | C++14 | 499 ms | 18944 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 fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int nax = 1e5 + 11;
const ll INF = 1e18;
int n, m, a, b, c;
int s, t;
int uu, vv;
vector <pair<int,int>> v[nax];
ll dis[3][nax];
priority_queue <pair<ll, int>> q;
bool odw[nax];
void dij(int pocz, int cnt) {
for(int i = 1; i <= n; ++i) {
dis[cnt][i] = INF;
odw[i] = 0;
}
dis[cnt][pocz] = 0;
q.push(mp(0, pocz));
while(!q.empty()) {
int ja = q.top().se;
q.pop();
if(odw[ja]) continue;
odw[ja] = 1;
for(auto it : v[ja]) {
ll nowa = dis[cnt][ja] + it.se;
if(nowa < dis[cnt][it.fi]) {
dis[cnt][it.fi] = nowa;
q.push(mp(-nowa, it.fi));
}
}
}
}
ll ans = INF;
ll path[nax];
ll odl[nax];
void algo() {
for(int i = 1; i <= n; ++i) {
odw[i] = 0;
odl[i] = INF;
path[i] = INF;
}
q.push(mp(0, t));
odl[t] = 0;
while(!q.empty()) {
int ja = q.top().se;
q.pop();
if(odw[ja]) continue;
odw[ja] = 1;
path[ja] = min(path[ja], dis[0][ja]);
if(odl[ja] + dis[2][ja] == dis[2][t])
ans = min(ans, dis[1][ja] + path[ja]);
for(auto it : v[ja]) {
ll nowa = odl[ja] + it.se;
if(nowa < odl[it.fi]) {
odl[it.fi] = nowa;
path[it.fi] = path[ja];
q.push(mp(-nowa, it.fi));
}
else if(nowa == odl[it.fi]) {
path[it.fi] = min(path[it.fi], path[ja]);
}
}
}
}
int main() {
scanf("%d %d", &n, &m);
scanf("%d %d", &s, &t);
scanf("%d %d", &uu, &vv);
for(int i = 1; i <= m; ++i) {
scanf("%d %d %d", &a, &b, &c);
v[a].pb(mp(b, c));
v[b].pb(mp(a, c));
}
dij(uu, 0);
dij(vv, 1);
dij(s, 2);
ans = min(ans, dis[0][vv]);
algo();
for(int i = 1; i <= n; ++i)
swap(dis[0][i], dis[1][i]);
algo();
printf("%lld\n", ans);
return 0;
}
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... |