이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#include "cyberland.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const double eps=1e-8;
const int maxn=1e5+10;
const double inf=1e15;
const int maxk=110;
int n,m,k,h;
vector<pair<int,int> > g[maxn];
double dist[maxn][maxk];
bool bio[maxn];
void dfs(int node){
if(bio[node]) return;
bio[node]=true;
for(auto [i,c]:g[node]){
if(bio[i]) continue;
dfs(i);
}
}
double solve(int _n,int _m,int _k, int _h,vector<int> x,vector<int> y,vector<int> c,vector<int> arr){
n=_n; m=_m; k=_k; h=_h;
k=min(k,68);
for(int i=0;i<n;i++) g[i].clear();
for(int i=0;i<n;i++) bio[i]=false;
for(int i=0;i<n;i++) for(int j=0;j<=k;j++) dist[i][j]=inf;
for(int i=0;i<m;i++){
if(x[i]==h || y[i]==h) continue;
g[x[i]].push_back({y[i],c[i]});
g[y[i]].push_back({x[i],c[i]});
}
dfs(0);
bool moze=false;
for(int i=0;i<m;i++){
if(x[i]==h || y[i]==h){
if(bio[x[i]] || bio[y[i]]) moze=true;
}
}
if(!moze) return -1;
priority_queue<tuple<double,int,int> > pq;
pq.push({0,0,0});
dist[0][0]=0;
for(int i=0;i<n;i++){
if(arr[i]==0 && bio[i]){
pq.push({0,i,0});
dist[i][0]=0;
}
}
while(!pq.empty()){
auto [cost,node,delio]=pq.top();
pq.pop();
cost=-cost;
if(cost>dist[node][delio]/*-eps*/) continue;
for(auto [i,c]:g[node]){
if(arr[i]==2){
if(cost+c<dist[i][delio]-eps){
dist[i][delio]=cost+c;
pq.push({-dist[i][delio],i,delio});
}
if(delio<k && cost+c<2*dist[i][delio+1]-eps){
dist[i][delio+1]=(cost+c)/2;
pq.push({-dist[i][delio+1],i,delio+1});
}
}else{
if(cost+c<dist[i][delio]-eps){
dist[i][delio]=cost+c;
pq.push({-dist[i][delio],i,delio});
}
}
}
}
double ret=inf;
for(int i=0;i<m;i++){
if(x[i]==h || y[i]==h){
if(x[i]!=h) for(int j=0;j<=k;j++) ret=min(ret,dist[x[i]][j]+c[i]);
if(y[i]!=h) for(int j=0;j<=k;j++) ret=min(ret,dist[y[i]][j]+c[i]);
}
}
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |