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 <bits/stdc++.h>
using namespace std;
#define int long long
vector<int32_t> powers;
vector<vector<pair<int,double>>> adj;
priority_queue<pair<double,pair<int,int>>,vector<pair<double,pair<int,int>>>,greater<>> q;
vector<bool> visited;
void dfs(int x){
if(visited[x])return;
visited[x]=true;
if(powers[x]==0)q.emplace(0, make_pair(x,0));
for(auto[dest,c]:adj[x])dfs(dest);
}
double solve(int32_t N, int32_t M, int32_t K, int32_t H, vector<int32_t> x, vector<int32_t> y, vector<int32_t> c, vector<int32_t> arr) {
swap(powers,arr);
visited = vector<bool>(N);
adj = vector<vector<pair<int,double>>>(N);
while(!q.empty())q.pop();
powers[0] = 0;
visited[H]=true;
for(int i=0;i<M;i++){
adj[x[i]].emplace_back(y[i],c[i]);
adj[y[i]].emplace_back(x[i],c[i]);
}
dfs(0);
vector<vector<bool>> vis(N,vector<bool>(K+1));
while(!q.empty()){
auto [tim,curr] = q.top();q.pop();
if(curr.first==H)return tim;
if(vis[curr.first][curr.second])continue;
vis[curr.first][curr.second]=true;
for(auto[dest,cost]:adj[curr.first]){
if(!vis[dest][curr.second])q.emplace(tim+cost,make_pair(dest,curr.second));
if(powers[dest]==2 and curr.second<K and !vis[dest][curr.second+1])q.emplace((tim+cost)/double(2),make_pair(dest,curr.second+1));
}
}
return -1;
}
//int32_t main() {
// int32_t T;
// assert(1 == scanf("%d", &T));
// while (T--){
// int32_t N,M,K,H;
// assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
// std::vector<int32_t> x(M);
// std::vector<int32_t> y(M);
// std::vector<int32_t> c(M);
// std::vector<int32_t> arr(N);
// for (int32_t i=0;i<N;i++)
// assert(1 == scanf("%d", &arr[i]));
// for (int32_t i=0;i<M;i++)
// assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
// printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
// }
//}
# | 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... |