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 "factories.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll N=5e5+5;
ll dist[N];
vector<pair<int,int>>adj[N];
void Init(int n,int a[],int b[],int d[]){
for(int i=0;i<n-1;i++){
adj[a[i]].pb({b[i],d[i]});
adj[b[i]].pb({a[i],d[i]});
}
}
ll Query(int s,int x[],int t,int y[]){
set<pair<ll,int>>st;
fill(dist,dist+N,1e18);
for(int i=0;i<s;i++){
st.insert({0,x[i]});
dist[x[i]]=0;
}
while(!st.empty()){
ll d=st.begin()->ff;
int i=st.begin()->ss;
st.erase(st.begin());
if(d!=dist[i]) continue;
for(auto [j,w]:adj[i]){
if(dist[i]+w<dist[j]){
dist[j]=dist[i]+w;
st.insert({dist[i]+w,j});
}
}
}
ll ans=1e18;
for(int i=0;i<t;i++){
ans=min(ans,dist[y[i]]);
}
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... |