Submission #1081547

#TimeUsernameProblemLanguageResultExecution timeMemory
1081547KasymKCyberland (APIO23_cyberland)C++17
97 / 100
3099 ms1375728 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> a){ 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]}); } vector<bool> vis(n, 0); queue<int> Q; Q.push(0); vis[0] = 1; while(!Q.empty()){ int x = Q.front(); Q.pop(); if(x == h) continue; for(auto &[i, w] : adj[x]) if(!vis[i]){ vis[i] = 1; Q.push(i); } } if(!vis[h]) return -1; using node = pair<double, int>; priority_queue<node, vector<node>, greater<node>> q[k+2]; vector<vector<bool>> mrk(n, vector<bool> (k+1, 0)); q[0].push({0, 0}); for(int i = 1; i < n; ++i) if(!a[i] and vis[i]) q[0].push({0, i}); int pk = 0; double answer = 1e18; while(pk <= k){ if(q[pk].empty()){ ++pk; continue; } auto [val, x] = q[pk].top(); q[pk].pop(); if(x == h){ umin(answer, val); mrk[x][pk] = 1; } if(mrk[x][pk]) continue; mrk[x][pk] = 1; for(auto [i, w] : adj[x]) if(a[i]){ if(!mrk[i][pk]) q[pk].push({val+w, i}); if(a[i] == 2) q[pk+1].push({(val+w)/2, i}); } } 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...