Submission #957106

#TimeUsernameProblemLanguageResultExecution timeMemory
957106irmuunFactories (JOI14_factories)C++17
15 / 100
8093 ms79576 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...