Submission #977705

#TimeUsernameProblemLanguageResultExecution timeMemory
977705UnforgettableplCyberland (APIO23_cyberland)C++17
44 / 100
32 ms10248 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<int32_t> powers; vector<vector<pair<int,int>>> adj; priority_queue<pair<int,int>,vector<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,x); 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,int>>>(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); visited = vector<bool>(N); while(!q.empty()){ auto [tim,idx] = q.top();q.pop(); if(idx==H)return tim; if(visited[idx])continue; visited[idx]=true; for(auto[dest,cost]:adj[idx])if(!visited[dest])q.emplace(cost+tim,dest); } 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...