Submission #787611

#TimeUsernameProblemLanguageResultExecution timeMemory
787611aymanrsCyberland (APIO23_cyberland)C++17
8 / 100
1996 ms2097152 KiB
#include <bits/stdc++.h> using namespace std; struct node { vector<pair<node*, int>> l; long long f = -1; bool g; }; void gfs(node* n, node* p){ for(auto [c, co] : n->l){ if(c!=p) gfs(c, n); n->g |= c->g; } } void dfs(node* n, node* p){ for(auto [c, co] : n->l){ if(c != p){ c->f = n->f + co; dfs(c, n); } } } 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){ node g[N]; g[0].g =true; for(int i = 0;i < M;i++){ g[x[i]].l.emplace_back(&g[y[i]], c[i]); g[y[i]].l.emplace_back(&g[x[i]], c[i]); } gfs(&g[H], NULL); for(auto [c, co] : g[H].l){ if(c->g) { c->f = co; dfs(c, &g[H]); } } long long ans = g[0].f; for(int i = 0;i < N;i++){ if(!arr[i] && g[i].f != -1) ans = min(ans, g[i].f); } return ans; } // int main(){ // cout << solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1}) << '\n'; // }
#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...