Submission #1171632

#TimeUsernameProblemLanguageResultExecution timeMemory
1171632Zero_OPRelay Marathon (NOI20_relaymarathon)C++20
17 / 100
6095 ms96204 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, l, r) for(int i = (l); i < (r); ++i) #define ROF(i, r, l) for(int i = (r)-1; i >= (l); --i) #define mp make_pair #define mt make_tuple #define ff first #define ss second #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define sz(v) (int)v.size() #define pb push_back #define eb emplace_back #define compact(v) v.erase(unique(all(v)), end(v)) #define dbg(x) "[" #x " = " << (x) << "]" template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } typedef long long ll; using db = double; using ull = unsigned long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vd = vector<db>; using vb = vector<bool>; using vpi = vector<pi>; using vpl = vector<pl>; void setIO(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); #endif } const int MAX = 1e5 + 5; const int inf = 1e9 + 9; int N, M, K, A[MAX], cnt_vis[MAX]; vpi adj[MAX]; vector<tuple<int, int, int>> important_pairs; bool is_special[MAX], done[MAX]; vector<pi> top[MAX]; vpi paths[MAX];; bool can(int v, int org, int cost){ if(v == org) return false; if(top[v].empty()) { top[v].eb(cost, org); return true; } for(auto &[tot, st] : top[v]){ if(st == org){ if(tot > cost){ tot = cost; sort(all(top[v])); return true; } else return false; } } if(sz(top[v]) < 4){ top[v].eb(cost, org); sort(all(top[v])); return true; } if(top[v][0].ff > cost){ top[v][0] = mp(cost, org); sort(all(top[v])); return true; } return false; } int main(){ setIO(); cin >> N >> M >> K; FOR(i, 0, M){ int u, v, w; cin >> u >> v >> w; adj[u].eb(v, w); adj[v].eb(u, w); } using node = tuple<int, int, int>; priority_queue<node, vector<node>, greater<node>> pq; while(K--){ int u; cin >> u; is_special[u] = true; pq.push(mt(0, u, u)); } while(!pq.empty()){ int dist, u, org; tie(dist, u, org) = pq.top(); pq.pop(); if(cnt_vis[u] == 500) break; ++cnt_vis[u]; for(auto [v, w] : adj[u]){ if(can(v, org, dist + w)){ pq.push(mt(dist + w, v, org)); } } } vector<tuple<int, int, int>> matches; FOR(i, 1, N+1){ if(is_special[i]){ for(auto [cost, org] : top[i]){ matches.eb(cost, min(i, org), max(i, org)); // cout << dbg(cost) << dbg(i) << dbg(org) << '\n'; } } } sort(all(matches)); compact(matches); multiset<int> online; for(auto [cost, x, y] : matches){ paths[x].eb(cost, y); paths[y].eb(cost, x); online.insert(cost); } int ans = inf; for(auto [cost, x, y] : matches){ online.erase(online.lower_bound(cost)); for(auto [len, z] : paths[x]) if(z != y) online.erase(online.lower_bound(len)); for(auto [len, z] : paths[y]) if(z != x) online.erase(online.lower_bound(len)); if(!online.empty()){ minimize(ans, *online.begin() + cost); } online.insert(cost); for(auto [len, z] : paths[x]) if(z != y) online.insert(len); for(auto [len, z] : paths[y]) if(z != x) online.insert(len); } cout << ans << '\n'; 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...