#include <vector>
#include <iostream>
#include <queue>
#include "cyberland.h"
using namespace std;
long double inf=1e17;
long double dp[100005][32];
vector<pair<int,int> >adj[100005];
priority_queue<pair<int,pair<long 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;
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;
long 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(dp[curr][layer]+cost<dp[vec][layer])
{
dp[vec][layer]=dp[curr][layer]+cost;
pq.push({layer,{-dp[vec][layer],vec}});
}
if(arr[vec]==0 && dp[vec][layer]!=0)
{
dp[vec][layer]=0;
pq.push({layer,{0,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}});
}
}
}
}
long double sol=inf;
for(i=0; i<=k; i++)
{
sol=min(sol,dp[fs][i]);
}
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<<solve(N, M, K, H, x, y, c, arr);
}
}*/
Compilation message
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(i=0; i<adj[curr].size(); i++)
| ~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3064 ms |
3160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1548 ms |
9960 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1369 ms |
7368 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
592 ms |
35488 KB |
Correct. |
2 |
Execution timed out |
3073 ms |
4172 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
990 ms |
7140 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
992 ms |
10216 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3049 ms |
4040 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3057 ms |
64368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |