답안 #794547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794547 2023-07-26T15:41:30 Z FEDIKUS 사이버랜드 (APIO23_cyberland) C++17
44 / 100
57 ms 74396 KB
#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,100);
  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 && false){
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 2772 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3668 KB Correct.
2 Correct 22 ms 4568 KB Correct.
3 Correct 22 ms 4484 KB Correct.
4 Correct 22 ms 4564 KB Correct.
5 Correct 22 ms 4564 KB Correct.
6 Correct 23 ms 12580 KB Correct.
7 Correct 34 ms 12512 KB Correct.
8 Correct 23 ms 21256 KB Correct.
9 Correct 22 ms 3448 KB Correct.
10 Correct 20 ms 3576 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3604 KB Correct.
2 Correct 23 ms 4368 KB Correct.
3 Correct 22 ms 4520 KB Correct.
4 Correct 22 ms 3156 KB Correct.
5 Correct 23 ms 3540 KB Correct.
6 Correct 8 ms 10356 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 57184 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3752 KB Correct.
2 Correct 22 ms 4532 KB Correct.
3 Correct 23 ms 4592 KB Correct.
4 Correct 24 ms 12836 KB Correct.
5 Correct 18 ms 3516 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3836 KB Correct.
2 Correct 19 ms 4408 KB Correct.
3 Correct 57 ms 74396 KB Correct.
4 Correct 17 ms 9960 KB Correct.
5 Correct 20 ms 3668 KB Correct.
6 Correct 20 ms 4224 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 3732 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 3636 KB Wrong Answer.
2 Halted 0 ms 0 KB -