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>
#define overload(a,b,c,d,...) d
#define rep1(a) for(ll _=0;_<(ll)a;++_)
#define rep2(i,n) for(ll i=0;i<(ll)n;++i)
#define rep3(i,l,r) for(ll i=(ll)l;i<(ll)r;++i)
#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
template<typename T,typename U>inline bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>inline bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}
static constexpr ll inf=numeric_limits<ll>::max()/2;
using vl=vector<ll>;
using ld=long double;
static constexpr ld eps=1e-9;
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int>y, std::vector<int> c, std::vector<int> arr){
chmin(K,100);
vector<vector<ld>>dist(N,vector<ld>(K+1,inf));
vector<vector<pair<ll,ll>>>g(N);
vl vis(N,0);
rep(i,M){
g[x[i]].eb(y[i],c[i]);
g[y[i]].eb(x[i],c[i]);
}
auto dfs=[&](auto&&dfs,int v)->void {
if(v==H)return;
for(auto [u,c]:g[v]){
if(vis[u])continue;
vis[u]=1;
dfs(dfs,u);
}
};
vis[0]=1;
dfs(dfs,0);
if(!vis[H])return -1;
priority_queue<tuple<ld,ll,ll>,vector<tuple<ld,ll,ll>>,greater<>>pq;
rep(i,N){
if(vis[i]&&(i==0||arr[i]==0)){
dist[i][K]=0;
pq.emplace(0,i,K);
}
}
rep(i,K){
priority_queue<tuple<ld,ll,ll>,vector<tuple<ld,ll,ll>>,greater<>>npq;
while(!pq.empty()){
auto [d,v,k]=pq.top();pq.pop();
if(dist[v][k]!=d)continue;
if(v==H)continue;
for(auto [u,cost]:g[v]){
if(dist[u][k]-(ld)(d+(ld)cost)>eps){
dist[u][k]=(ld)(d+(ld)cost);
pq.emplace(dist[u][k],u,k);
}
if(k-1>=0&&arr[u]==2&&dist[u][k-1]-(ld)(d+(ld)cost)/2.0>eps){
dist[u][k-1]=(ld)(d+(ld)cost)/2.0;
npq.emplace(dist[u][k-1],u,k-1);
}
}
}
pq=move(npq);
}
ld res=inf;
rep(i,K+1)chmin(res,dist[H][i]);
if(res==inf)return -1;
return res;
}
# | 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... |