Submission #996408

#TimeUsernameProblemLanguageResultExecution timeMemory
996408phoenixCrocodile's Underground City (IOI11_crocodile)C++17
100 / 100
759 ms68772 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 10; const ll INF = 1e15; struct set2 { ll val[3]; set2() { val[0] = val[1] = val[2] = INF; } void insert(ll x) { val[2] = x; if(val[1] > val[2]) swap(val[1], val[2]); if(val[0] > val[1]) swap(val[0], val[1]); if(val[1] > val[2]) swap(val[1], val[2]); } }; set2 dp[N]; vector<pair<int, int>> g[N]; int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) { for(int i = 0; i < m; i++) { g[R[i][0]].push_back({R[i][1], L[i]}); g[R[i][1]].push_back({R[i][0], L[i]}); } set<pair<ll, int>> q; for(int i = 0; i < k; i++) { dp[P[i]].insert(0); dp[P[i]].insert(0); } for(int i = 0; i < n; i++) { q.insert({dp[i].val[1], i}); } bool vis[N] = {}; while(!q.empty()) { int s = q.begin()->second; if(dp[s].val[1] == INF) break; q.erase(q.begin()); vis[s] = 1; for(auto [to, w] : g[s]) { if(vis[to]) continue; q.erase({dp[to].val[1], to}); dp[to].insert(dp[s].val[1] + w); q.insert({dp[to].val[1], to}); } } return dp[0].val[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...