Submission #1081504

#TimeUsernameProblemLanguageResultExecution timeMemory
1081504KasymKCyberland (APIO23_cyberland)C++17
49 / 100
3099 ms548312 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ vector<pii> adj[n]; for(int i = 0; i < m; ++i){ adj[x[i]].pb({y[i], c[i]}); adj[y[i]].pb({x[i], c[i]}); } // wr; queue<int> q; vector<bool> vis0(n, 0); q.push(0); // we start at node 0 vis0[0] = 1; while(!q.empty()){ int x = q.front(); q.pop(); if(x == h) continue; // h-a baramyzdan sonra goni durmaly bolyas for(auto [i, w] : adj[x]) if(!vis0[i]){ vis0[i] = 1; q.push(i); } } // wr; if(!vis0[h]) return -1; // pq.1 = my weight, pq.2 = which node, pq.3 = how many times I used special power 2 priority_queue<tuple<double, int, int>, vector<tuple<double, int, int>>, greater<tuple<double, int, int>>> pq; pq.push({0, 0, 0}); for(int i = 0; i < n; ++i) if(arr[i] == 0 and vis0[i]) pq.push({0, i, 0}); // we can start at this points // wr; double answer = 1e18; vector<vector<bool>> vis(n, vector<bool> (k+1, 0)); while(!pq.empty()){ double val; int x, cnt; tie(val, x, cnt) = pq.top(); pq.pop(); if(vis[x][cnt]) continue; vis[x][cnt] = 1; if(x == h){ umin(answer, val); continue; } for(auto &[i, w] : adj[x]){ if(!vis[i][cnt]) pq.push({val+w, i, cnt}); if(arr[i] == 2 and cnt < k and !vis[i][cnt+1]) pq.push({(val+w)/(double)2, i, cnt+1}); } } return answer; } // int main(){ // double kk = solve(3, 2, 30, 2,{1, 2},{2, 0},{12, 4},{1, 2, 1}); // double kk1 = solve(4, 4, 30, 3,{0, 0, 1, 2},{1, 2, 3, 3},{5, 4, 2, 4},{1, 0, 2, 1}); // if(kk == 4.0 and kk1 == 2.0) // puts("Correct."); // else // puts("Wrong Answer."); // 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...