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 "cyberland.h"
#include<bits/stdc++.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<vector<pair<int,int>>> g(N);
for (int i=0; i<M; i++){
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
int dist = -1;
vector<bool> seen(N, false);
priority_queue<pair<double,int>> pq;
pq.push({(double) 0, 0});
while (!pq.empty()){
double d = -pq.top().first;
int cur = pq.top().second;
pq.pop();
if (cur == H){
dist = d;
break;
}
if (seen[cur]) continue;
seen[cur] = true;
for (pair<int,int> next : g[cur]) pq.push({-(d+next.second), next.first});
}
return dist;
unordered_set<int> s;
seen.clear();
seen.resize(N, false);
queue<int> q;
q.push(0);
while (!q.empty()){
int cur = q.front();
q.pop();
if (cur == H) continue;
if (seen[cur]) continue;
seen[cur] = true;
if (arr[cur] == 0) s.insert(cur);
for (pair<int,int> next : g[cur]) q.push(next.first);
}
seen.clear();
seen.resize(N, false);
while (!pq.empty()) pq.pop();
pq.push({(double) 0, H});
while (!pq.empty()){
double d = -pq.top().first;
int cur = pq.top().second;
pq.pop();
if (s.find(cur) != s.end()){
if (d < dist) return d;
else break;
}
if (seen[cur]) continue;
seen[cur] = true;
for (pair<int,int> next : g[cur]) pq.push({-(d+next.second), next.first});
}
return dist;
}
# | 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... |