Submission #750187

#TimeUsernameProblemLanguageResultExecution timeMemory
750187singlabharatCyberland (APIO23_cyberland)C++17
15 / 100
1078 ms29620 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; using si = set<int>; using mii = map<int, int>; #define sz(x) (int)size(x) #define pb emplace_back #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define fr first #define sc second #define fo(i, end) for (int i = 0; i < end; i++) #define foo(i, start, end) for (int i = start; i < end; i++) template<typename T> inline void domin(T &x, T y) {if (y < x) x = y;} template<typename T> inline void domax(T &x, T y) {if (y > x) x = y;} template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &a) { os << '{'; string sep; for (const T &x : a) os << sep << x, sep = ", "; return os << '}';} void debug() {cerr << endl;} template <typename Head, typename... Tail> void debug(Head h, Tail... t) {cerr << h << ' '; debug(t...);} #ifdef singlabharat #define debug(...) cerr << "(" << #__VA_ARGS__ << ") : ", debug(__VA_ARGS__) #else #define debug(...) #endif const int MX = 2e5 + 2, MOD = 1e9 + 7; double INF = 1e18; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { domin(K, 80); vector<vpii> g(N); fo(i, M) { g[x[i]].pb(pair(y[i], c[i])); g[y[i]].pb(pair(x[i], c[i])); } using state = tuple<double, int, int>; vb vis(N); queue<int> q; q.push(0); vis[0] = true; while (!empty(q)) { int u = q.front(); q.pop(); for (auto [v, _] : g[u]) { if (!vis[v]) { vis[v] = true; q.push(v); } } } // {dist, divs, u} priority_queue < state, vector<state>, greater<state>> pq; vector<vector<double>> dist(N, vector<double>(K + 1, INF)); // min dist till u with k divs done pq.push({0.0, 0, 0}); dist[0][0] = 0.0; fo(u, N) { if (arr[u] == 0 and vis[u]) { pq.push({0.0, 0, u}); dist[u][0] = 0.0; } } while (!empty(pq)) { auto [_, divs, u] = pq.top(); pq.pop(); if (u == H) continue; for (auto [v, w] : g[u]) { if (arr[u] == 0) { if (w < dist[v][divs]) { dist[v][divs] = w; pq.push({dist[v][divs], divs, v}); } } else if (arr[u] == 1) { if (dist[u][divs] + w < dist[v][divs]) { dist[v][divs] = dist[u][divs] + w; pq.push({dist[v][divs], divs, v}); } } else { if (divs < K and dist[u][divs] / 2 + w < dist[v][divs + 1]) { dist[v][divs + 1] = dist[u][divs] / 2 + w; pq.push({dist[v][divs + 1], divs + 1, v}); } } } } double ans = *min_element(begin(dist[H]), end(dist[H])); return (ans == INF ? -1 : 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...