Submission #759749

#TimeUsernameProblemLanguageResultExecution timeMemory
759749OrazBCyberland (APIO23_cyberland)C++17
49 / 100
3072 ms2097152 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //set.find_by_order(x) x-position value //set.order_of_key(x) number of strictly less elements don't need *set.?? #define N 100005 #define wr cout << "Continue debugging\n"; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <double, int> #define pb push_back #define ff first #define ss second int vis[N]; vector<pair<int,int>> E[N]; double F(int x){ double res = 1.0; while(x--) res *= 2; return res; } void dfs(int nd, int h, vector<int> arr, vector<int> &z){ if (!arr[nd]) z.pb(nd); vis[nd] = 1; for (auto i : E[nd]){ if (i.ff == h or vis[i.ff]) continue; dfs(i.ff, h, arr, z); } } double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ for (int i = 0; i < n; i++){ vis[i] = 0; E[i].clear(); } for (int i = 0; i < m; i++){ E[x[i]].pb({y[i], c[i]}); E[y[i]].pb({x[i], c[i]}); } vector<int> z = {0}; vector<double> dis(n+1, 1e15); dis[0] = 0; dfs(0, h, arr, z); double ans = 1e15; set<pii> q; for (auto i : z){ dis[i] = 0; q.insert({0, i}); } for (int i = 0; i <= k; i++){ vector<bool> chk(n, 0); while(!q.empty()){ int x = (*q.begin()).ss; q.erase(q.begin()); if (x == h) continue; for (auto j : E[x]){ double res = dis[x]+j.ss; if (arr[x] == 2) res = (dis[x]/F(i))+j.ss; if (dis[j.ff] > res){ q.erase({dis[j.ff], j.ff}); dis[j.ff] = res; chk[j.ff] = 1; q.insert({dis[j.ff], j.ff}); } } } for (int j = 0; j < n; j++) if (chk[j] and arr[j] == 2) q.insert({dis[j], j}); ans = min(ans, dis[h]); } if (ans == 1e15) return double(-1); return ans; } // int main () // { // int n, m, k, h; // cin >> n >> m >> k >> h; // vector<int> x(m), y(m), c(m), arr(n); // for (int i = 0; i < m; i++){ // cin >> x[i] >> y[i] >> c[i]; // } // for (int i = 0; i < n; i++) cin >> arr[i]; // cout << solve(n,m,k,h,x,y,c,arr); // }
#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...