이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
#include <vector>
#define ff first
#define ss second
#define ll long long
const double INF=1e18;
using namespace std;
ll h,i,j;
vector<pair<ll,double>> v[200001];
bitset<200005> vis;
priority_queue<pair<double,ll>> q;
double dp[200001][31],dist;
void dfs(ll a){
if(a==h) return;
if(vis[a]) return;
vis[a]=1;
for(pair<ll,double> l:v[a]){
dfs(l.ff);
}
}
void dijkstra(ll t){
while(!q.empty()){
ll a=q.top().ss;
double d=q.top().ff;
q.pop();
if(dp[a][t]!=-1) continue;
dp[a][t]=-d;
if(a!=h) for(pair<ll,double> l:v[a]){
if(dp[l.ff][t]==-1) q.push({d-l.ss,l.ff});
}
}
}
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) {
h=H;
dist=INF;
K=min(K,30);
for(i=0;i<M;i++){
v[x[i]].push_back({y[i],c[i]});
v[y[i]].push_back({x[i],c[i]});
}
dfs(0);
q.push({0,0});
for(i=0;i<N;i++){
if(vis[i]==1 && arr[i]==0) q.push({0,i});
for(j=0;j<=K;j++){
dp[i][j]=-1;
}
}
dijkstra(0);
for(j=1;j<=K;j++){
for(i=0;i<N;i++){
if(vis[i]==1 && arr[i]==2){
for(pair<ll,double> l:v[i])
q.push({-1*(dp[i][j-1]/2)-l.ss,l.ff});
}
}
dijkstra(j);
}
vis.reset();
for(i=0;i<N;i++){
v[i].clear();
}
for(j=0;j<=K;j++){
if(dp[H][j]!=-1) dist=min(dist,dp[H][j]);
}
return (dist==INF ? -1 : dist);
}
# | 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... |