# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884535 | Trisanu_Das | Cyberland (APIO23_cyberland) | C++17 | 32 ms | 7004 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 p = *s.begin();
s.erase(s.begin());
int u = p.second, curr_d = p.first;
for(auto [v, c] : adj[p.second]){
if(curr_d + c < dist[v]){
auto f = s.find(make_pair(dist[v], v));
if(f != s.end()) s.erase(f);
dist[v] = curr_d + c;
s.insert({dist[v], v});
}
}
}
if(dist[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, c] : adj[u]) if(!vis[v]) {
vis[v] = true;
q.push(v);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |