int main() { ifstream f("retea2.in"); ofstream g("retea2.out"); f>>n>>m; for(int i=1; i<=n; ++i) f>>p[i].x>>p[i].y; int bi; for(int i=1;i<=m; ++i) { f>>p[i+n].x>>p[i+n].y; dmin[i]=INF; for(int j=1; j<=n; ++j) dmin[i]=min(dmin[i],dist(p[j],p[i+n])); if(bd>dmin[i]) { bd=dmin[i]; bi=i; } b.insert(i); } for(;b.size();) { b.erase(b.find(bi)); cst+=bd; bd=INF; for(is i=b.begin(); i!=b.end(); ++i) dmin[*i]=min(dmin[*i],dist(p[bi+n],p[*i+n])); for(is i=b.begin(); i!=b.end(); ++i) if(bd>dmin[*i]) { bd=dmin[*i]; bi=*i; } } g<<fixed<<setprecision(6)<<cst; cout<<fixed<<setprecision(6)<<cst; return 0; }
void remove_sets_not_containing(const uint x){ if(fix.find(x) == fix.end()){ // if x in fix, then x is already in all sets if(variable.find(x) != variable.end()){ // if x is optional, then make it madatory fix.insert(x); variable.erase(x); } else clear(); // if x is not in any set, then remove all sets } }
// remove all sets that (do not) contain an item void remove_sets_containing(const uint x){ if(fix.find(x) == fix.end()) // if x not in fix, then just remove all occurances of it from variable variable.erase(x); else clear(); // if x in fix, then all sets contain x, so clear the compact_set }
// check containment of (lists of) items in all/some of the sets bool all_sets_contain(const uint x) const{ return fix.find(x) != fix.end(); }
bool some_sets_contain(const uint x) const{ return (fix.find(x) != fix.end()) || (variable.find(x) != variable.end()); }
// add or remove a (list of) items from all sets inline void add_to_all(const uint x){ fix.insert(x); }
inline void remove_all_from_all(const uint x){ fix.erase(x); variable.erase(x); }
// return whether there are some elements that are fix inline bool has_no_fixed_elements() const { return fix.empty(); }
// multiply all sets in the list with all subsets of X (add all subsets to all sets in the list) inline void multiply_with_subsets(const list<uint>& X){ for(uint x: X) variable.insert(x); }
// multiply all sets in the list with one set X (add this set to all sets in the list) inline void multiply_with_set(const list<uint>& X){ for(uint x: X) fix.insert(x); }
// clear inline void clear(){ fix.clear(); variable.clear(); }
// return whether the list contains no element bool empty() const{ return fix.empty() && variable.empty(); }