# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884531 | Trisanu_Das | Cyberland (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
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>
#include "cyberland.h"
using namespace std;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
vector<pair<int, int> > adj[N];
for(int i = 0; i < M; i++){
adj[x[i]].push_back({y[i], c[i]});
adj[y[i]].push_back({x[i], c[i]});
}
long long dist[N];
fill(dist, dist + N, LLONG_MAX);
dist[H] = 0;
set<pair<long long, int> > s;
s.insert({0, H});
while(!s.empty()){
auto latest = *s.begin();
s.erase(s.begin());
for(auto [c, co] : adj[latest.second]){
if(latest.first + co < d[c]) {
auto f = s.find({dist[c], c});
if(f != s.end()) s.erase(f);
dist[c] = latest.first + co;
s.insert({dist[c], c});
}
}
}
if(d[0 == LLONG_MAX]) return -1;
long long ans = dist[0];
queue<int> q;
q.push(0);
bool vis[N] = {false};
vis[0] = vis[H] = true;
while(!q.empty()){
int u = q.front();
q.pop();
if(!arr[u]) ans = min(ans, dist[u]);
for(auto [v, co] : adj[u]){
if(!vis[v]){
vis[v] = true;
q.push(v);
}
}
}
return ans;
}