This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define ll long long
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
const ll N=1e5+9;
pair<ll,ll>p;
ll vis[N],a[N],g;
vector<pair<ll,ll>>v[N];
vector<ll>o;
priority_queue<pair<ll,ll>>q;
void dfs(ll node)
{
if(vis[node])return;
vis[node]=1;
if(!a[node])o.push_back(node);
for(auto i:v[node])dfs(i.second);
}
double solve(int n, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<ll>dis(n,1e18);
double ans=1e9+9;
o.clear();
o.push_back(0);
for(ll i=0;i<n;++i)
{
a[i]=arr[i];
vis[i]=0,v[i].clear();
}
for(ll i=0;i<M;++i)
{
v[x[i]].push_back({c[i],y[i]});
v[y[i]].push_back({c[i],x[i]});
}
dfs(0);
for(ll i=0;i<n;++i)vis[i]=0;
dis[H]=0;
q.push({H,0});
while(q.size())
{
p=q.top();
g=p.second;
q.pop();
if(vis[g])continue;
vis[g]=1;
for(auto i:v[g])
{
if(dis[g]+i.first<dis[i.second])
{
dis[i.second]=dis[g]+i.first;
q.push({-dis[i.second],i.second});
}
}
}
for(auto i:o)ans=min(ans,double(i));
if(ans==1e9+9)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... |