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>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T>
bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T>
bool chmin(T &a, T b) { return b < a ? (a = b, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 100010;
const ll inf = 1ll << 55;
int n, m, S, T, S2, T2;
ll ds[MAX_N], dt[MAX_N], d1[MAX_N], d2[MAX_N];
vector<pair<int,int>> edge[MAX_N];
vector<int> dage[MAX_N], reve[MAX_N];
void dij(int s, ll* dis) {
static bool vis[MAX_N];
fill(vis, vis+n+1, false);
fill(dis, dis+n+1, inf);
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>> > pq;
dis[s] = 0;
pq.emplace(0, s);
while (pq.size()) {
auto [len, x] = pq.top(); pq.pop();
if (vis[x]) continue;
vis[x] = true;
for (auto [u, w] : edge[x])
if (!vis[u] && chmin(dis[u], dis[x] + w))
pq.emplace(dis[u], u);
}
}
int od[MAX_N], ol;
void getod() {
vector<int> deg(n+1);
for (int i = 1;i <= n;++i)
for (int u : dage[i])
++deg[u];
for (int i = 1;i <= n;++i) if (deg[i] == 0)
od[ol++] = i;
for (int i = 0;i < ol;++i) {
int x = od[i];
for (int u : dage[x])
if (--deg[u] == 0) od[ol++] = u;
}
}
ll dagdp() {
getod();
ll res = min(d1[S] + d2[S], d1[T2]);
for (int i = 0;i < ol;++i) {
int x = od[i];
if (dage[x].size() + reve[x].size() == 0) continue;
DE(x);
chmin(res, d1[x] + d2[x]);
for (int u : reve[x])
chmin(res, min(d1[u] + d2[x], d1[x] + d2[u]));
for (int u : reve[x])
chmin(d1[x], d1[u]), chmin(d2[x], d2[u]);
}
return res;
}
ll solve() {
dij(S, ds), dij(T, dt), dij(S2, d1), dij(T2, d2);
ll len = ds[T];
DE(len);
for (int i = 1;i <= n;++i)
for (auto [u, w] : edge[i]) if (ds[i] + w + dt[u] == len)
dage[i].pb(u), reve[u].pb(i);
return dagdp();
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m >> S >> T >> S2 >> T2;
for (int a, b, c, i = 0;i < m;++i) {
cin >> a >> b >> c;
edge[a].pb(b, c);
edge[b].pb(a, c);
}
cout << solve() << '\n';
}
Compilation message (stderr)
commuter_pass.cpp: In function 'll dagdp()':
commuter_pass.cpp:18:17: warning: statement has no effect [-Wunused-value]
18 | #define DE(...) 0
| ^
commuter_pass.cpp:67:3: note: in expansion of macro 'DE'
67 | DE(x);
| ^~
commuter_pass.cpp: In function 'll solve()':
commuter_pass.cpp:18:17: warning: statement has no effect [-Wunused-value]
18 | #define DE(...) 0
| ^
commuter_pass.cpp:82:2: note: in expansion of macro 'DE'
82 | DE(len);
| ^~
# | 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... |