Submission #884536

#TimeUsernameProblemLanguageResultExecution timeMemory
884536Trisanu_DasCyberland (APIO23_cyberland)C++17
44 / 100
31 ms9812 KiB
#include <bits/stdc++.h> using namespace std; 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){ vector<pair<int, int>> g[N]; for(int i = 0;i < M;i++){ g[x[i]].emplace_back(y[i], c[i]); g[y[i]].emplace_back(x[i], c[i]); } long long d[N]; fill(d, d+N, LONG_LONG_MAX); d[H] = 0; set<pair<long long, int>> s; s.insert(make_pair(0, H)); while(!s.empty()){ auto p = *s.begin(); s.erase(s.begin()); for(auto [c, co] : g[p.second]){ if(p.first + co < d[c]){ auto f = s.find(make_pair(d[c], c)); if(f != s.end()) s.erase(f); d[c] = p.first+co; s.insert(make_pair(d[c], c)); } } } if(d[0] == LONG_LONG_MAX) return -1; long long ans = d[0]; queue<int> q; q.push(0); bool v[N] = {false}; v[0] = v[H] = true; while(!q.empty()){ int t = q.front(); q.pop(); if(!arr[t]) ans = min(ans, d[t]); for(auto [c, co] : g[t]) if(!v[c]) { v[c] = true; q.push(c); } } return ans; }
#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...