Submission #818974

#TimeUsernameProblemLanguageResultExecution timeMemory
81897412345678Cyberland (APIO23_cyberland)C++17
100 / 100
187 ms80448 KiB
#include "cyberland.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define node tuple<double, int, int>
 
const int nx=1e5+5, kx=70;
double p[kx+2];
bool can[nx];
 
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) {
    K=min(K, 70);
    priority_queue<node, vector<node>, greater<node>> pq;
    vector<vector<pair<int, double>>> d(N+2);
    vector<vector<double>> dp(N, vector<double>(K+2, DBL_MAX));
    vector<vector<bool>> vs(N, vector<bool>(K+2, 0));
    queue<int> q;
    for (int i=0; i<N; i++) can[i]=0;
    for (int i=0; i<M; i++) 
    {
        d[x[i]].emplace_back(y[i], c[i]);
        d[y[i]].emplace_back(x[i], c[i]);
    }
    q.emplace(0);
    can[H]=1;
    while (!q.empty())
    {
        int x=q.front();
        q.pop();
        if (can[x]) continue;
        can[x]=1;
        for (auto [y, z]:d[x]) if (!can[y]) q.push(y);
    }
    p[0]=1;
    for (int i=1; i<=K; i++) p[i]=p[i-1]/2;
    dp[H][0]=0; arr[0]=0;
    pq.emplace(0, H, 0);
    while (!pq.empty())
    {
        auto [cw, cl, ck]=pq.top();
        pq.pop();
        if (vs[cl][ck]) continue;
        vs[cl][ck]=1;
        if (arr[cl]==0&&can[cl]) return cw;
        for (auto [v, w]:d[cl])
        {
            if (!can[v]||v==H) continue;
            double nw=cw+w*p[ck];
            if (nw<dp[v][ck]) dp[v][ck]=nw, pq.emplace(nw, v, ck);
            if (arr[v]==2&&ck<K&&nw<dp[v][ck+1]) dp[v][ck+1]=nw, pq.emplace(nw, v, ck+1); 
        }
    }
    return -1;
}
#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...