Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef complex<double> V;
typedef vector<P> vecP;
typedef pair<P,P> L;
typedef pair<P,P> S;
typedef pair<P,double> C;
const double eps=1e-8;
const double PI=acos(-1);
const double PI2=PI*2.0;
 
namespace std{
  bool operator < (const P &a,const P &b){
    return (a.real()!=b.real()?
            a.real() <b.real():
            a.imag() <b.imag());
  }
};
 
V normal(V a){
  assert( abs(a)>0 );
  return a/abs(a);
}
 
double Sqrt( double x ){
  if(x<0)return 0;
  else return sqrt(x);
}
 
P Vector(L a){
  return a.second-a.first;
}
 
bool eq(double a,double b){
  return (-eps<a-b&&a-b<eps);
}
 
bool eq(P a,P b){
  return ( eq(a.real(),b.real()) && eq(a.imag(),b.imag()) );
}
 
double dot(P a,P b){
  return real(b*conj(a));
}
 
double cross(P a,P b){
  return imag(b*conj(a));
}
 
double getArg(P a,P b){
  return arg(b*conj(a));
}
 
double getTime(V a,V b){
  assert( eq(cross(a,b),0) );
  return ( dot(a,b) < 0 ? -1.0 : 1.0 ) * abs(b) / abs(a);
}
 
 
P project(P a,P b,P c){
  b-=a,c-=a;
  return a+b*real(c/b);
}
 
P reflect(P a,P b,P c){
  b-=a,c-=a;
  return a+b*conj(c/b);
}
 
int ccw(P a,P b,P c){
  P ab=b-a,ac=c-a;
  P k=ac*conj(ab);
  if(k.imag()>0)return 1;
  if(k.imag()<0)return -1;
  if(k.real()<0)return 2;
  if(abs(ab)<abs(ac))return -2;
  return 0;
}
 
bool isParallel(P a,P b){
  return eq(0, cross(a,b));
}
 
bool isParallel(S a,S b){
  return eq(0, cross( Vector(a) , Vector(b) ) );
}
 
bool onLP(L l,P p){
  P a=l.first, b=l.second;
  return eq(0, cross(b-a,p-a));
}
 
bool onSP(S s,P p){
  P a=s.first, b=s.second;
  return eq( abs(b-a) , abs(a-p)+abs(b-p) );
}
 
bool isCrossSS(S s0,S s1){
  P a=s0.first, b=s0.second;
  P c=s1.first, d=s1.second;
  int f0 = ccw(a,b,c) * ccw(a,b,d);
  int f1 = ccw(c,d,a) * ccw(c,d,b);
  return (f0<=0 && f1<=0);
}
 
bool isCrossLS(L l,S s){
  P a=l.first, b=l.second;
  P c=s.first, d=s.second;
  return ( ccw(a,b,c) * ccw(a,b,d) <= 0 );
}
 
double distLP(L l,P p){
  P a=l.first, b=l.second;
  double res = cross(b-a,p-a) / abs(b-a);
  return abs(res);
}
 
double distSP(S s,P p){
  P a=s.first, b=s.second;
  if( dot(b-a,p-a) < eps )return abs(p-a);
  if( dot(a-b,p-b) < eps )return abs(p-b);
  return distLP(s,p);
}
 
double distSS(S s0,S s1){
  if( isCrossSS(s0,s1) )return 0;
  double res0 = min( distSP( s0, s1.first ) , distSP(s0, s1.second) );
  double res1 = min( distSP( s1, s0.first ) , distSP(s1, s0.second) );
  return min(res0,res1);
}
 
P getCrossLL(L l0,L l1){
  P a=l0.first, b=l0.second;
  P c=l1.first, d=l1.second;
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
 
  
int inPolygon(vecP &t,P p){
  int n=t.size();
  double sum=0;
  for(int i=0;i<n;i++){
    P a=t[i],b=t[(i+1==n?0:i+1)];
    if( ccw(a,b,p)==0 )return 1;
    sum+= getArg(a-p,b-p);
  }
  if( abs(sum) < eps )return 0;
  else return 2;
}


struct edge{
  int to;
  double cost;
};

typedef vector<edge> Node;
typedef vector<Node> Graph;
Graph G;
map<int,bool> isB;
vector< P > points;

void segments2graph( vector<S> segments ,vector<P> b ){

  int n=segments.size();

  sort(b.begin(),b.end());
  
  for(int i=0;i<(int)b.size();i++){
    points.push_back(b[i]);
  }
  
  for(int i=0;i<n;i++){
    S si=segments[i];
    points.push_back( si.first );
    points.push_back( si.second );
    for(int j=0;j<i;j++){
      S sj=segments[j];
      if( isCrossSS( si , sj ) && !isParallel( si, sj ) ){
        points.push_back( getCrossLL(si,sj) );
      }
    }
  }
 
  sort(points.begin(), points.end());
  points.erase( unique( points.begin(), points.end() ) , points.end() );
   
  G.resize(points.size());
  
  for(int i=0;i<(int)points.size();i++){
    P p=points[i];
    isB[i] = binary_search(b.begin(),b.end(), p);
  }
  
  typedef pair< double , int > Pair;
     
  for(int i=0;i<n;i++){
    S si=segments[i];
    P sf=si.first, se=si.second;
    vector< Pair > targets;
    for(int j=0;j<(int)points.size();j++){
      P pj=points[j];
      // if( ccw( si.first, si.second, pj ) == 0 ){
      if( onSP( si, pj ) ){
        targets.push_back( Pair(getTime(se-sf ,pj-sf ), j ) );
      }
    }

    for(int j=0;j<(int)targets.size();j++){
      for(int k=0;k<j;k++){
        Pair a=targets[j];
        Pair b=targets[k];
        P ap=points[ a.second ];
        P bp=points[ b.second ];
        G[a.second].push_back( (edge){ b.second , abs(ap-bp) } );
        G[b.second].push_back( (edge){ a.second , abs(bp-ap) } );
      }
    }

    /* 
    sort( targets.begin(), targets.end() );
    for(int j=0;j+1<(int)targets.size();j++){
      Pair a=targets[j];
      Pair b=targets[j+1];
      P ap=points[ a.second ];
      P bp=points[ b.second ];
      
      G[a.second].push_back( (edge){ b.second , abs(ap-bp) } );
      G[b.second].push_back( (edge){ a.second , abs(bp-ap) } );
    }
    */
    
  }

}

P input(){
  double x,y;
  cin>>x>>y;
  return P(x,y);
}


map<int,bool> visited;
double total=0;

map< P , bool > counted;

void dfs(int pos){
  
  if( isB[pos] )return;
  if(visited[pos])return;
  visited[pos]=true;
  
  for(int i=0;i<(int)G[pos].size();i++){
    edge e=G[pos][i];
    if( visited[e.to] || isB[e.to] )total+=e.cost;
    else total += e.cost/2.0;
  }
  
  for(int i=0;i<(int)G[pos].size();i++){
    edge e=G[pos][i];
    dfs(e.to);
  }
}

int main(){
  int N,M;
  cin>>N>>M;
  vector< S > segments;
  vector< P > bs;

  double ans = 0;
  
  for(int i=0;i<N;i++){
    P a=input();
    P b=input();
    segments.push_back( S(a,b) );
    ans+= abs(a-b);
  }
  
  for(int i=0;i<M;i++){
    P a=input();
    bs.push_back( b );
  }
  
  P si,ti;
  si=input();
  ti=input();
  points.push_back(si);
  points.push_back(ti);
  
  segments2graph(segments,bs);

  
  int ex = lower_bound( points.begin(), points.end() , si ) - points.begin();
  int root = lower_bound( points.begin(), points.end() , ti ) - points.begin();
  
  dfs(root);
  
  if( visited[ex] ){
    cout<<"-1"<<endl;
    return 0;
  }
  
  total = 0;
  dfs( ex );
  printf("%.10f\n",ans-total);
  return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:287:19: error: 'b' was not declared in this scope
  287 |     bs.push_back( b );
      |                   ^