제출 #366665

#제출 시각아이디문제언어결과실행 시간메모리
366665yrn_alfCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
625 ms40612 KiB
#pragma GCC optimize("Ofast,unroll-loops,shrink-wrap-separate,loop-nest-optimize,inline") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #include <bits/stdc++.h> #include <tr1/unordered_map> #include <tr1/unordered_set> // #include <ext/rope> #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> #include <ext/pb_ds/tree_policy.hpp> #define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define mt make_tuple #define mp make_pair #define pb push_back #define eb emplace_back #define mat vector<vector<ll>> #define mat2 vector<vector<mat>> #define vi vector<int> #define vll vector<ll> #define lll __int128_t #define psi pair<string, int> #define pis pair<int, string> #define pic pair<int, char> #define pcc pair<char, char> #define pii pair<int, int> #define pll pair<ll, ll> #define piiii pair<pii, pii> #define mii map<int, int> #define umii tr1::unordered_map<int, int> #define iter set<int>::iterator #define lb lower_bound #define ub upper_bound #define lg2(n) (31 - __builtin_clz(n)) #define lg2ll(n) (63 - __builtin_clzll(n)) #define fi first #define se second /* #define fi first.first #define se first.second #define th second.first #define fo second.second */ /* #define piii pair<int, pii> #define fi first #define se second.fi #define th second.second */ /* #define piii pair<pii, int> #define fi first.first #define se first.th #define th second */ #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; // using namespace __gnu_cxx; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef tree<pll, null_type, greater<pll>, rb_tree_tag, tree_order_statistics_node_update> ost; const int nax = 400005, block = 320, dax = 2, lim = 2187, lgax = 25, bit = 29, mod = 1000000007, inf = 1000000007; const ll llax = 1e18; const ld pi = acos(0) * 2; const double eps = 1e-6; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); /* const int MAX_MEM = 100000000; int mpos; char mem[MAX_MEM]; inline void* operator new(size_t n) { assert((mpos += n) <= MAX_MEM); return (void*)(mem + mpos - n); } inline void operator delete(void*) {} */ inline int read() { char c = getchar_unlocked(); int t = 0, f = 1; while (!isdigit(c) && c != EOF) f = (c == '-' ? -1 : 1), c = getchar_unlocked(); while (isdigit(c) && c != EOF) t = t * 10 + c - '0', c = getchar_unlocked(); return t * f; } inline void read(char* s) { char c = getchar_unlocked(); while (isspace(c)) c = getchar_unlocked(); while (!isspace(c)) *s++ = c, c = getchar_unlocked(); *s = '\0'; } /* struct chash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; */ int n, m; ll d[2][nax], c[nax], dp[nax]; pii e[nax]; vector<pll> g[nax]; bitset<nax> vis; void dijkstra(int s, int k) { priority_queue<pll, vector<pll>, greater<pll>> q; q.push({0, s}); fill(d[k], d[k] + nax, llax); d[k][s] = 0; while (!q.empty()) { ll v = q.top().se, cur_d = q.top().fi; q.pop(); if (cur_d > d[k][v]) continue; for (pll ch : g[v]) if (d[k][ch.fi] > d[k][v] + max(c[ch.se], c[ch.se ^ 1])) q.push({d[k][ch.fi] = d[k][v] + max(c[ch.se], c[ch.se ^ 1]), ch.fi}); } } ll dfs(int v) { if (vis[v]) return dp[v]; vis[v] = 1; for (pll ch : g[v]) if (!c[ch.se]) dp[v] = min(dp[v], dfs(ch.fi)); return dp[v]; } int main() { // IOS ll ans = llax; n = read(), m = read(); int s = read(), t = read(), x = read(), y = read(); for (int i = 0; i < 2 * m; ++i) { int v = read(), u = read(), w = read(); g[v].eb(u, i), c[i] = w; e[i] = {v, u}; ++i; g[u].eb(v, i), c[i] = w; e[i] = {u, v}; } dijkstra(x, 0); ans = d[0][y]; dijkstra(s, 0); dijkstra(t, 1); for (int j = 0; j < 2 * m; ++j) { if (d[0][e[j].fi] + c[j] + d[1][e[j].se] == d[0][t]) c[j] = 0; } dijkstra(x, 0); dijkstra(y, 1); for (int i = 1; i <= n; ++i) dp[i] = d[1][i]; dfs(s); for (int i = 1; i <= n; ++i) ans = min(ans, d[0][i] + dp[i]); vis = 0; dijkstra(y, 0); dijkstra(x, 1); for (int i = 1; i <= n; ++i) dp[i] = d[1][i]; dfs(s); for (int i = 1; i <= n; ++i) ans = min(ans, d[0][i] + dp[i]); printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...