Submission #1094222

#TimeUsernameProblemLanguageResultExecution timeMemory
1094222anhthiCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
307 ms64456 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define mp(x, y) make_pair(x, y) #define sz(v) ((int) (v).size()) #define all(v) (v).begin(), (v).end() #define MASK(i) (1LL << (i)) #define BIT(x, y) (((x) >> (y)) & 1) #define pb push_back #define max_rng *max_element #define min_rng *min_element #define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i) #define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i) #define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i) template <class X, class Y> inline bool maximize(X &x, Y y) { return (x < y ? x = y, true : false); } template <class X, class Y> inline bool minimize(X &x, Y y) { return (x > y ? x = y, true : false); } template <class X> inline void compress(vector<X> &a) { sort(all(a)); a.resize(unique(all(a)) - a.begin()); } int ctz(ll x) { return __builtin_ctzll(x); } int lg(ll x) { return 63 - __builtin_clzll(x); } int popcount(ll x) { return __builtin_popcount(x); } mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return l + abs((ll) rng()) % (r - l + 1); } const ll oo = (ll) 1e17; const int inf = (ll) 2e9 + 7, mod = (ll) 998244353; const int mxn = 2e5 + 5, mxm = MASK(5) + 1, LOG = 18; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } void sub(int &x, int y) { x -= y; if (x < 0) x += mod; } struct Edge { int v, w; Edge(int _v, int _w) : v(_v), w(_w) {}; }; int n, m; vector<Edge> g[mxn]; bool vis[mxn]; pair<int, int> a[4]; bool update(pair<int, int> &best, pair<int, int> &secondBest, pair<int, int> cur) { a[0] = cur; a[1] = best; a[2] = secondBest; sort(a, a + 3); best = a[0]; int dist = secondBest.first; secondBest = a[1].second == best.second ? a[2] : a[1]; return dist > secondBest.first; } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { n = N; m = M; forn(i, 0, m - 1) { int u = R[i][0]; int v = R[i][1]; g[u].pb(Edge(v, L[i])); g[v].pb(Edge(u, L[i])); } vector<pair<int, int>> best(n, mp(inf, inf)), secondBest; secondBest = best; forn(i, 0, K - 1) { int node = P[i]; best[node] = secondBest[node] = mp(0, 0); } priority_queue<pair<int, int>> pq; forn(i, 0, n - 1) if (secondBest[i].first != inf) { pq.push(mp(0, i)); } memset(vis, 0, sizeof vis); while (!pq.empty()) { pair<ll, int> top = pq.top(); pq.pop(); int u = top.second; ll dist = -top.fi; if (vis[u]) continue; vis[u] = true; for (Edge i : g[u]) { int v = i.v; ll nxt = dist + i.w; if (update(best[v], secondBest[v], mp(nxt, u))) { pq.push(mp(-secondBest[v].first, v)); } } } return secondBest[0].first; } //int main(void) { // // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); // // #define TASK "task" // if (fopen(TASK".inp", "r")) { // freopen(TASK".inp", "r", stdin); // freopen(TASK".out", "w", stdout); // } // // int n = 6, m = 6, k = 3; // int r[][2] = {{0, 1}, {0, 2}, {2, 5}, {2, 4}, {1, 4}, {1, 3}}; // int l[] = {3, 3, 3, 5, 5, 3}; // int p[] = {3, 4, 5}; // // cout << travel_plan(n, m, r, l, k, p); // // return 0; //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...