# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756223 | activedeltorre | Sequence (APIO23_sequence) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <iostream>
#include <queue>
#include <iomanip>
#pragma GCC optimize ("O3")
#include "cyberland.h"
using namespace std;
long double inf=1e17;
double dp[100005][55];
vector<pair<int,int> >adj[100005];
priority_queue<pair<int,pair<double,int> > >pq;
double solve(int n,int m,int k,int fs,vector<int>x,vector<int>y,vector<int>cst,vector<int>arr)
{
int i,j;
k=min(k,40);
for(i=0; i<m; i++)
{
adj[x[i]].push_back({y[i],cst[i]});
adj[y[i]].push_back({x[i],cst[i]});
}
for(i=0; i<n; i++)
{
for(j=0; j<=k; j++)
{
dp[i][j]=inf;
}
}
dp[0][0]=0;
pq.push({0,{0,0}});
int layer,curr,vec;
double timp,cost;
while(pq.size())
{
layer=pq.top().first;
timp=pq.top().second.first;
curr=pq.top().second.second;
pq.pop();
if(dp[curr][layer]==-timp && curr!=fs)
{
for(i=0; i<adj[curr].size(); i++)
{
vec=adj[curr][i].first;
cost=adj[curr][i].second;
if(arr[vec]==0 && dp[vec][layer]!=0)
{
dp[vec][layer]=0;
pq.push({layer,{0,vec}});
}
else if(dp[curr][layer]+cost<dp[vec][layer])
{
dp[vec][layer]=dp[curr][layer]+cost;
pq.push({layer,{-dp[vec][layer],vec}});
}
if(arr[vec]==2 && dp[curr][layer]+cost<dp[vec][layer+1]*2)
{
dp[vec][layer+1]=(dp[curr][layer]+cost)/2;
pq.push({layer+1,{-dp[vec][layer+1],vec}});
}
}
}
}
double sol=inf;
for(i=0; i<=k; i++)
{
sol=min(sol,dp[fs][i]);
}
for(i=0;i<=n;i++)
{
adj[i].clear();
}
if(sol==inf)
{
return -1;
}
return sol;
}
/*
int main()
{
int T;
cin>>T;
while (T--)
{
int N,M,K,H;
cin>>N>>M>>K>>H;
std::vector<int> x(M);
std::vector<int> y(M);
std::vector<int> c(M);
std::vector<int> arr(N);
for (int i=0; i<N; i++)
cin>>arr[i];
for (int i=0; i<M; i++)
{
cin>>x[i]>>y[i]>>c[i];
}
cout<<setprecision(12)<<solve(N, M, K, H, x, y, c, arr)<<'\n';
}
}
*/