# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
937655 | Baytoro | Cyberland (APIO23_cyberland) | 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 "cyberland.h"
#include <bits/stdc++.h>
#include "stub.cpp"
using namespace std;
#define ll long long
//#define int ll
#define pb push_back
#define tt pair<int,pair<int,int>>
#define fr first
#define sc second.first
#define tr second.second
const ll N1=1e5+5,INF=1e18;
double dist[N1][33];
vector<pair<int,int>> g[N1];
int a[N1];
int used[N1];
void djks(int x, int h, int n){
priority_queue<tt,vector<tt>,greater<tt>> pq;
for(int i=0;i<n;i++){
if(used[i] && (i==0 || a[i]==0)){
pq.push({0,{i,0}});
dist[i][0]=0;
}
}
while(!pq.empty()){
tt tmp=pq.top();
pq.pop();
int cur=tmp.sc,t=tmp.tr;
if(cur==h) continue;
if(abs(dist[cur][t]-tmp.fr)>1e-9) continue;
for(auto it: g[cur]){
if(dist[it.first][t]>dist[cur][t]+it.second){
dist[it.first][t]=dist[cur][t]+it.second;
pq.push({dist[it.first][t],{it.first,t}});
}
if(t==30) continue;
if(a[it.first]==2){
if(dist[it.first][t+1]>(dist[cur][t]+it.second)/2){
dist[it.first][t+1]=(dist[cur][t]+it.second)/2;
pq.push({dist[it.first][t+1],{it.first,t+1}});
}
}
}
}
}
void dfs(int x, int h){
if(x==h) return;
used[x]=1;
for(auto it: g[x]){
if(!used[it.first])
dfs(it.first,h);
}
}
double solve(int n, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
for(int i=0;i<n;i++){
for(int j=0;j<=31;j++)
dist[i][j]=INF;
g[i].clear();
used[i]=0;
}
for(int i=0;i<M;i++){
g[x[i]].pb({y[i],c[i]});
g[y[i]].pb({x[i],c[i]});
}
for(int i=0;i<n;i++)
a[i]=arr[i];
dfs(0,H);
djks(0,H,n);
double ans=INF;
for(int i=0;i<=K;i++){
ans=min(ans,dist[H][i]);
}
if(ans==INF) return -1;
else return ans;
}