Submission #750010

#TimeUsernameProblemLanguageResultExecution timeMemory
750010CookieCyberland (APIO23_cyberland)C++17
100 / 100
1996 ms128952 KiB
#include<bits/stdc++.h> #include "cyberland.h" #include<fstream> using namespace std; ifstream fin("VNOICUP.INP"); ofstream fout("VNOICUP.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const int mxn = 1e5; const ll prec = 1e-6; struct ch{ int u, take; ld dd; }; struct cmp{ bool operator()(const ch &a, const ch &b){ return(a.dd > b.dd); } }; vt<pii>adj[mxn + 1]; ld d[mxn + 1][71]; bool vis[mxn + 1], go[mxn + 1][71]; void dfs(int s){ vis[s] = 1; for(auto [v, w]: adj[s]){ if(!vis[v])dfs(v); } } double solve(int n, int m, int k, int h, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) { k = min(k, 70); forr(i, 0, n){ adj[i].clear(); forr(j, 0, k + 1){ d[i][j] = 1e18; go[i][j] = 0; } vis[i] = 0; } forr(i, 0, m){ int u = x[i], v = y[i], w = c[i]; adj[u].pb({v, w}); adj[v].pb({u, w}); } dfs(0); if(!vis[h])return(-1); d[0][0] = 0; for(int tt = 0; tt <= k; tt++){ priority_queue<ch, vt<ch>, cmp>pq; for(int i = 0; i < n; i++){ if(d[i][tt] != 1e18)pq.push({i, tt, d[i][tt]}); } while(!pq.empty()){ auto [u, take, dd] = pq.top(); pq.pop(); if((abs(dd - d[u][take]) > prec) || u == h)continue; for(auto [v, w]: adj[u]){ if(arr[v] == 0 && d[v][tt] != 0){ d[v][tt] = 0; pq.push({v, tt, d[v][tt]}); continue; } if(d[v][take] > d[u][take] + w){ d[v][take] = d[u][take] + w; pq.push({v, take, d[v][take]}); } if(arr[u] == 2 && take < k){ d[v][take + 1] = min(d[v][take + 1], (d[u][take] / 2.0) + w); } } } } ld ans = 1e18; for(int i = 0; i <= k; i++)ans = min(ans, d[h][i]); return(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...