제출 #977867

#제출 시각아이디문제언어결과실행 시간메모리
977867Unforgettablepl사이버랜드 (APIO23_cyberland)C++17
49 / 100
3086 ms799304 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...