제출 #920234

#제출 시각아이디문제언어결과실행 시간메모리
920234Mher777Cyberland (APIO23_cyberland)C++17
15 / 100
3010 ms2097152 KiB
#include "cyberland.h" #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <fstream> using namespace std; /* -------------------- Typedefs -------------------- */ typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef float fl; typedef long double ld; /* -------------------- Usings -------------------- */ using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; /* -------------------- Defines -------------------- */ #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"Yes\n" #define no cout<<"No\n" #define all(x) (x).begin(), (x).end() /* -------------------- Constants -------------------- */ const int MAX = int(2e9 + 5); const ll MAXL = ll(1e18) + 5ll; const ll MOD = ll(1e9 + 7); const ll MOD2 = ll(998244353); const int N = 100005; vector<pair<int, ld>> g[N]; vector<ld> d[N]; int n, m, k, h; int used[N]; void dfs(int u = 0) { used[u] = 1; for (auto to : g[u]) { if (!used[to.ff]) dfs(to.ff); } } void clr() { for (int i = 0; i < n; ++i) { g[i].clear(); d[i].clear(); used[i] = 0; } } 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) { n = N, m = M, k = K, h = H; for (int i = 0; i < m; ++i) { g[x[i]].pub({ y[i],(ld)c[i] }); g[y[i]].pub({ x[i],(ld)c[i] }); } dfs(); if (!used[h]) { clr(); return -1; } d[0].resize(k + 1); d[0][0] = 0; priority_queue<pair<ld, pii>> pq; pq.push({ 0,{0,0} }); for (int i = 1; i < n; ++i) { if (used[i]) d[i].resize(k + 1); else continue; for (int j = 0; j <= k; ++j) d[i][j] = (ld)1e15; if (arr[i] == 0) { pq.push({ 0,{i,0} }); d[i][0] = 0; } } while (!pq.empty()) { int u = pq.top().ss.ff; int ind = pq.top().ss.ss; ld w = -pq.top().ff; pq.pop(); if (w > d[u][ind]) continue; for (auto to : g[u]) { if (d[to.ff][ind] > d[u][ind] + to.ss) { d[to.ff][ind] = d[u][ind] + to.ss; pq.push({ -d[to.ff][ind],{to.ff,ind} }); } if (arr[to.ff] == 2 && ind != k) { if (d[to.ff][ind + 1] > ((d[u][ind] + to.ss) / (ld)2)) { d[to.ff][ind + 1] = ((d[u][ind] + to.ss) / (ld)2); pq.push({ -d[to.ff][ind + 1],{to.ff,ind + 1} }); } } } } ld ans = d[h][0]; for (int i = 1; i <= k; ++i) { ans = min(ans, d[h][i]); } clr(); return ans; } /* 2 3 2 30 2 1 2 1 1 2 12 2 0 4 4 4 30 3 1 0 2 1 0 1 5 0 2 4 1 3 2 2 3 4 */
#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...