Submission #714168

#TimeUsernameProblemLanguageResultExecution timeMemory
714168gaga999Commuter Pass (JOI18_commuter_pass)C++17
100 / 100
325 ms22480 KiB
#include <cstdio> #include <stdio.h> #include <iostream> #include <math.h> #include <vector> #include <queue> #include <stack> #include <deque> #include <algorithm> #include <utility> #include <set> #include <map> #include <stdlib.h> #include <cstring> #include <string.h> #include <string> #include <sstream> #include <assert.h> #include <climits> #include <sstream> #include <numeric> #include <time.h> #include <limits.h> #include <list> #include <bitset> #include <unordered_map> #include <unordered_set> #include <random> #include <iomanip> #include <complex> #include <chrono> // #pragma GCC optimize("Ofast,no-stack-protector") // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt") #define lowbit(x) ((x) & -(x)) #define ml(a, b) ((1ll * (a) * (b)) % M) #define tml(a, b) (a) = ((1ll * (a) * (b)) % M) #define ad(a, b) ((0ll + (a) + (b)) % M) #define tad(a, b) (a) = ((0ll + (a) + (b)) % M) #define mi(a, b) ((0ll + M + (a) - (b)) % M) #define tmi(a, b) (a) = ((0ll + M + (a) - (b)) % M) #define tmin(a, b) (a) = min((a), (b)) #define tmax(a, b) (a) = max((a), (b)) #define iter(a) (a).begin(), (a).end() #define riter(a) (a).rbegin(), (a).rend() #define init(a, b) memset((a), (b), sizeof(a)) #define cpy(a, b) memcpy((a), (b), sizeof(a)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define pb push_back #define mpr make_pair #define ls(i) ((i) << 1) #define rs(i) ((i) << 1 | 1) #define INF 0x3f3f3f3f #define eps 1e-9 #define F first #define S second #define N 100005 #define AC cin.tie(0)->sync_with_stdio(0) using namespace std; typedef long long llt; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<llt, llt> pll; typedef pair<llt, int> pli; typedef complex<double> cd; // const int M = 998244353; // random_device rm; // mt19937 rg(rm()); // default_random_engine rg(rm()); // uniform_int_distribution<int> rd(INT_MIN, INT_MAX); // uniform_real_distribution<double> rd(0, M_PI); void db() { cout << "\n"; } template <class T, class... U> void db(T a, U... b) { cout << a << " ", db(b...); } vector<pii> eg[N]; llt ds[N], dt[N], du[N], dv[N], su[N], sv[N], tu[N], tv[N], an, stv; bool vd[N]; int n, m, s, t, u, v; struct P { pli u; pll uv; bool operator<(const P &rh) const { return u > rh.u; } }; void dij1(int p, llt *dp) { fill(dp, dp + n + 1, 1ll << 60), init(vd, 0); priority_queue<pli, vector<pli>, greater<pli>> pq; dp[p] = 0, pq.push(mpr(0, p)); while (!pq.empty()) { pli tp = pq.top(); pq.pop(); if (vd[tp.S]) continue; vd[tp.S] = 1; for (pii v : eg[tp.S]) if (!vd[v.S] && v.F + tp.F < dp[v.S]) pq.push(mpr(dp[v.S] = v.F + tp.F, v.S)); } } void dij2(int p, llt *dp, llt *nu, llt *nv) { fill(dp, dp + n + 1, 1ll << 60), init(vd, 0); fill(nu, nu + n + 1, 1ll << 60), fill(nv, nv + n + 1, 1ll << 60); priority_queue<P> pq; dp[p] = 0, nu[p] = du[p], nv[p] = dv[p]; pq.push({mpr(0, p), mpr(nu[p], nv[p])}); while (!pq.empty()) { P tp = pq.top(); pq.pop(); if (tp.u.F == dp[tp.u.S]) tmin(nu[tp.u.S], tp.uv.F), tmin(nv[tp.u.S], tp.uv.S); if (vd[tp.u.S]) continue; vd[tp.u.S] = 1; tmin(nu[tp.u.S], du[tp.u.S]), tmin(nv[tp.u.S], dv[tp.u.S]); for (pii v : eg[tp.u.S]) if (!vd[v.S] && v.F + tp.u.F <= dp[v.S]) pq.push({mpr(dp[v.S] = v.F + tp.u.F, v.S), mpr(nu[tp.u.S], nv[tp.u.S])}); } } signed main() { int x, y, w; scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v); for (int i = 0; i < m; i++) { scanf("%d%d%d", &x, &y, &w); eg[x].pb(mpr(w, y)); eg[y].pb(mpr(w, x)); } dij1(u, du), dij1(v, dv); dij2(s, ds, su, sv), dij2(t, dt, tu, tv); assert(du[v] == dv[u]), assert(ds[t] == dt[s]); an = min(du[v], dv[u]), stv = min(ds[t], dt[s]); for (int i = 1; i <= n; i++) { // db(su[i], sv[i], tu[i], tv[i]); if (ds[i] + dt[i] <= stv) { tmin(an, su[i] + tv[i]); tmin(an, sv[i] + tu[i]); } } printf("%lld\n", an); }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:134:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |     scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:137:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |         scanf("%d%d%d", &x, &y, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...