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;
#include <vector>
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, double>> adj[N];
for(int i = 0; i < M; ++i) {
adj[x[i]].emplace_back(y[i], c[i]);
adj[y[i]].emplace_back(x[i], c[i]);
}
double dist[N];
for(int i = 0; i < N; ++i) dist[i] = -1;
dist[0] = 0;
queue<int> q;
q.push(0);
if(1) { // first bfs
queue<int> qq;
bool vis[N] = {};
vis[0] = 1;
qq.push(0);
while(!qq.empty()) {
int a = qq.front();
qq.pop();
if(a == H) continue;
if(arr[a] == 0) {
dist[a] = 0;
q.push(a);
}
for(auto [b, w] : adj[a]) {
if(vis[b]) continue;
vis[b] = 1;
qq.push(b);
}
}
}
while(!q.empty()) {
int a = q.front();
q.pop();
for(auto [b, w] : adj[a]) {
if(dist[b] != -1) continue;
dist[b] = dist[a] + w;
q.push(b);
}
}
return dist[H];
/* vector<pair<int, double>> adj[N]; */
/* for(int i = 0; i < M; ++i) { */
/* adj[x[i]].emplace_back(y[i], c[i]); */
/* adj[y[i]].emplace_back(x[i], c[i]); */
/* } */
/* double dist[N]; */
/* for(int i = 0; i < N; ++i) dist[i] = -1; */
/* priority_queue<pair<double, int>> pq; */
/* for(int i = 1; i < N; ++i) { */
/* if(arr[i] == 0 || i == 0) { */
/* dist[i] = 0; */
/* pq.emplace(-dist[i], i); */
/* } */
/* } */
/* while(!pq.empty()) { */
/* int a = pq.top().second; */
/* double d = -pq.top().first; */
/* pq.pop(); */
/* if(dist[a] < d || a == H) { */
/* continue; */
/* } */
/* for(auto [b, w] : adj[a]) { */
/* if(dist[b] == -1 || d + w < dist[b]) { */
/* dist[b] = d + w; */
/* pq.emplace(-dist[b], b); */
/* } */
/* } */
/* } */
/* return dist[H]; */
}
# | 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... |