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;
#define f(i,a,b) for(int i = a;i < b;i++)
#define ll long long
#define ii pair<ll,ll>
#define F first
#define S second
#define pb push_back
priority_queue<ii,vector<ii>,greater<ii> >pq;
bool v[100005] = {0};
ll dist[100005];
vector<vector<ii> >adj;
ll H;
void dfs(ll idx){
v[idx] = 1;
for(auto x:adj[idx]){
if(!v[x.F] && x.F != H){
dfs(x.F);
}
}
}
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) {
double ans;
H = h;
adj.assign(n+5,vector<ii>());
f(i,0,n){
v[i] = 0;
dist[i] = 1e18;
}
f(i,0,m){
adj[x[i]].pb(ii(y[i],c[i]));
adj[y[i]].pb(ii(x[i],c[i]));
}
dfs(0);
f(i,0,n){
if((arr[i] == 0 && v[i]) || i == 0){
pq.push(ii(0,i));
dist[i] = 0;
}
}
while(!pq.empty()){
ii f = pq.top();
pq.pop();
ll w = f.F,u = f.S;
if(dist[u] < w){
continue;
}
for(auto x:adj[u]){
if(dist[x.F] > dist[u] + x.S){
dist[x.F] = dist[u] + x.S;
pq.push(ii(dist[x.F],x.F));
}
}
}
ans = dist[h];
if(dist[h] == 1e18){
ans = -1;
}
return ans;
}
# | 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... |