이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
void dfs(int x , vector<bool>&reach , vector<vector<pair<int ,int>>> &adj)
{
if(reach[x])
return ;
reach[x] = 1;
for(auto [u , cost] : adj[x])
dfs(u , reach , adj);
}
using Node = tuple<double , int , int>;
priority_queue<Node , vector<Node> , greater<Node>> pq;
void upd(int x , int k , int d , vector<vector<double>> &dist)
{
if(dist[x][k] > d)
{
dist[x][k] = d;
pq.push({d , x , k});
}
}
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)
{
pq = priority_queue<Node , vector<Node> , greater<Node>> ();
K = min(K , 70);
vector<vector<pair<int , int>>> adj(N);
vector<bool> reach(N);
vector<double> pwr(K + 1);
pwr[0] = 1;
for(int i = 1 ; i <= K ; i++)
{
pwr[i] = pwr[i - 1]/2.0;
}
for(int i = 0 ; i < M ; i++)
{
adj[x[i]].push_back({y[i] , c[i]});
adj[y[i]].push_back({x[i] , c[i]});
}
vector<vector<double>> dist(N , vector<double>(K + 1 , 1e16));
arr[0] = 0;
pq.push({0 , H , 0});
dist[H][0] = 0;
dfs(0 , reach ,adj);
vector<vector<bool>> vis(N , vector<bool>(K + 1));
while(!pq.empty())
{
auto [d , x , k] = pq.top();
pq.pop();
if(vis[x][k])
continue;
vis[x][k] = true;
if(arr[x] == 0)
{
return d;
}
for(auto [u , cost] : adj[x])
{
if(!reach[u])
continue;
cost*=pwr[k];
upd(u , k , cost + d , dist);
}
if(arr[x] == 2)
{
for(int p = k + 1 ; p <= K ; p++)
{
for(auto [u , cost] : adj[x])
{
if(!reach[u])
continue;
cost*=pwr[p];
upd(u , p , cost + d , dist);
}
}
}
}
return -1;
}
# | 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... |