# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
969027 | kshitiz101 | Cyberland (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
const int N=1e5+10;
vector<pair<ll,ll>> adj[N];
ll n,m,h,k;
void solve()
{
cin>>m>>k>>h;
vector<ll> first,second,third;
for(int i=0;i<m;i++)
{
ll p;
cin>>p;
first.push_back(p);
}
for(int i=0;i<m;i++)
{
ll p;
cin>>p;
second.push_back(p);
}
for(int i=0;i<m;i++)
{
ll p;
cin>>p;
third.push_back(p);
}
ll type[n];
for(auto &p:type)
cin>>p;
for(int i=0;i<m;i++)
{
adj[first[i]].push_back({second[i],third[i]});
adj[second[i]].push_back({first[i],third[i]});
}
priority_queue<tuple<ld,ll,ll>,vector<tuple<ld,ll,ll>>,greater<tuple<ld,ll,ll>>> pq;
pq.push({0.0,0,0});
ld ans[n][k+1];
for(int i=1;i<n;i++)
{
for(int j=0;j<k;j++)
ans[i][j]=1e15;
}
while(pq.size())
{
auto it=pq.top();
pq.pop();
ld dist=get<0>(it);
ll node=get<1>(it);
ll usedk=get<2>(it);
if(ans[node][usedk]<dist||node==h)
continue;
for(auto &p:adj[node])
{
ld e=dist+(long double)p.second;
if(type[p.first]==0)
e=0;
if(usedk<k&&type[p.first]==2)
{
if(ans[p.first][usedk]>e)
{
ans[p.first][usedk]=e;
pq.push({e,p.first,usedk});
}
if(ans[p.first][usedk+1]>(e/2.0))
{
ans[p.first][usedk+1]=(e/2.0);
pq.push({e/2.0,p.first,usedk+1});
}
}
else
{
if(ans[p.first][usedk]>e)
{
ans[p.first][usedk]=e;
pq.push({e,p.first,usedk});
}
}
}
}
ld final=1e15;
for(int i=0;i<=k;i++)
final=min(final,ans[h][i]);
cout<<final<<endl;
}
int main()
{
while(cin>>n)
{
solve();
}
}