Submission #959916

#TimeUsernameProblemLanguageResultExecution timeMemory
959916GrindMachineCrocodile's Underground City (IOI11_crocodile)C++17
89 / 100
2035 ms62924 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; #include "crocodile.h" vector<pii> adj1[N], adj2[N]; vector<int> dp(N); vector<bool> spl(N); vector<bool> vis(N); vector<int> topo; void dfs1(int u){ vis[u] = 1; for(auto [v,w] : adj2[u]){ if(vis[v]) conts; dfs1(v); } topo.pb(u); } int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) { rep(i,m){ int u = R[i][0], v = R[i][1], w = L[i]; adj1[u].pb({v,w}), adj1[v].pb({u,w}); } rep(i,k){ spl[P[i]] = 1; } while(true){ bool changed = false; rep(u,n){ if(spl[u]){ dp[u] = 0; conts; } vector<int> vals; for(auto [v,w] : adj1[u]){ vals.pb(dp[v]+w); } sort(all(vals)); int new_val = inf1; if(sz(vals) >= 2) new_val = vals[1]; if(new_val != dp[u]){ changed = true; } dp[u] = new_val; } if(!changed) break; } int ans = dp[0]; return ans; // priority_queue<pll,vector<pll>,greater<pll>> pq; // vector<ll> dis(n+5,inf2); // pq.push({0,0}); // while(!pq.empty()){ // auto [cost,u] = pq.top(); // pq.pop(); // if(vis[u]) conts; // vis[u] = 1; // dis[u] = cost; // for(auto [v,w] : adj1[u]){ // pq.push({cost+w,v}); // } // } // rep1(u,n){ // for(auto [v,w] : adj1[u]){ // if(dis[u]+w == dis[v]){ // adj2[u].pb({v,w}); // } // } // } // fill(all(vis),0); // dfs1(0); // trav(u,topo){ // if(spl[u]){ // dp[u] = 0; // conts; // } // vector<int> vals; // for(auto [v,w] : adj2[u]){ // vals.pb(dp[v]+w); // } // sort(all(vals)); // if(sz(vals) < 2){ // dp[u] = inf1; // } // else{ // dp[u] = vals[1]; // } // } // int ans = dp[0]; // return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...