Language: C++

#include<map>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

const int maxn = 110;
const double eps = 1e-7;
int N,ncnt = 1,cnt,tot; bool exist[maxn][maxn];

inline int gi()
{
	char ch; int ret = 0,f = 1;
	do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');
	if (ch == '-') f = -1,ch = getchar();
	do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');
	return ret*f;
}

inline int dcmp(double a)
{
	if (a > eps) return 1;
	else if (a < -eps) return -1;
	else return 0;
}

struct Point
{
	double x,y;
	Point() = default;
	Point(double _x,double _y):x(_x),y(_y) {}
	void read() { x = gi(),y = gi(); }
	double angle() const { return atan2(y,x); }
	friend bool operator <(const Point &a,const Point &b)
	{
		if (dcmp(a.x-b.x)) return dcmp(a.x-b.x) < 0;
		else return dcmp(a.y-b.y) < 0;
	}
	friend Point operator +(const Point &a,const Point &b) { return Point(a.x+b.x,a.y+b.y); }
	friend Point operator -(const Point &a,const Point &b) { return Point(a.x-b.x,a.y-b.y); }
	friend Point operator *(const Point &a,double b) { return Point(a.x*b,a.y*b); }
	friend Point operator *(double b,const Point &a) { return Point(a.x*b,a.y*b); }
	friend Point operator /(const Point &a,double b) { return Point(a.x/b,a.y/b); }
	friend double operator *(const Point &a,const Point &b) { return a.x*b.x+a.y*b.y; }
	friend double operator /(const Point &a,const Point &b) { return a.x*b.y-a.y*b.x; }
}P[maxn*maxn],tp[maxn],V;
map <Point,int> M;

struct Line
{
	Point p,v;
	Line() = default;
	Line(const Point &_p,const Point &_v):p(_p),v(_v) {}
};

struct Segment
{
	int from,to,id; bool sur;
	Segment(int _from = 0,int _to = 0,int _id = 0,bool _sur = false):from(_from),to(_to),id(_id),sur(_sur) {}
	friend bool operator <(const Segment &a,const Segment &b) { return (P[a.to]-P[a.from]).angle() < (P[b.to]-P[b.from]).angle(); }
}edge[maxn*maxn*maxn];
vector <int> G[maxn*maxn];

inline bool cmp(const Point &a,const Point &b) { return a*V<b*V; }
inline bool cmpG(int a,int b) { return edge[a] < edge[b]; }

inline void nadd(int u,int v) { ++ncnt; G[u].push_back(ncnt); edge[ncnt] = Segment(u,v); }
inline void nins(int u,int v) { /*cerr << u << ' ' << v << endl;*/ nadd(u,v); nadd(v,u); }

inline Point CrossPoint(const Line &a,const Line &b)
{
	Point u = a.p-b.p;
	double t = (b.v/u)/(a.v/b.v);
	return a.p+(a.v*t);
}

inline bool Intersect(const Point &a,const Point &b,const Point &c,const Point &d)
{
	if (!dcmp((b-a)/(d-c))) return false;
	if (dcmp((c-a)/(b-a))*dcmp((d-a)/(b-a)) > 0) return false;
	if (dcmp((a-c)/(d-c))*dcmp((b-c)/(d-c)) > 0) return false;
	return true;
}

void prepare(const Point &a,const Point &b)
{
	vector <Point> vec;
	V = b-a; double lim = V*V;
	for (int i = 1;i <= cnt;++i)
	{
		if (dcmp(V/(P[i]-a))) continue;
		double t = V*(P[i]-a);
		if (dcmp(t) < 0) continue;
		if (dcmp(t-lim) > 0) continue;
		vec.push_back(P[i]);
	}
	sort(vec.begin(),vec.end(),cmp);
	for (int i = 1;i < (int)vec.size();++i)
		nins(M[vec[i-1]],M[vec[i]]);
}

double work()
{
	double ret = 0;
	for (int i = 1;i <= cnt;++i) sort(G[i].begin(),G[i].end(),cmpG);
	for (int i = 1;i <= cnt;++i)
	{
		int nn = G[i].size();
		for (int j = 0;j < nn;++j)
			edge[G[i][j]].id = j;
	}
	for (int i = 2;i <= ncnt;++i)
		if (!edge[i].sur)
		{
			int j = i,p,nn; vector <Point> vec;
			while (!edge[j].sur)
			{
				edge[j].sur = true; vec.push_back(P[edge[j].from]);
				p = edge[j].to; nn = G[p].size();
				j ^= 1; j = G[p][(edge[j].id+1)%nn];
			}
			double res = 0; nn = vec.size();
			for (j = 0;j < nn;++j)
				res += (vec[j]-vec[0])/(vec[(j+1)%nn]-vec[0]);
			if (res < 0) ret += res;
		}
	return -ret/2;
}

int main()
{
	// freopen("B.in","r",stdin);
	N = gi();
	for (int i = 1;i <= N;++i)
	{
		tp[i].read();
		if (M.find(tp[i]) == M.end())
			P[M[tp[i]] = ++cnt] = tp[i];
	}
	for (int i = 1;i < N;++i)
		for (int j = i+1;j < N;++j)
			if (Intersect(tp[i],tp[i+1],tp[j],tp[j+1]))
			{
				Point c = CrossPoint(Line(tp[i],tp[i+1]-tp[i]),Line(tp[j],tp[j+1]-tp[j]));
				if (M.find(c) == M.end())
					P[M[c] = ++cnt] = c;
			}
	for (int i = 1;i < N;++i)
	{
		int a = M[tp[i]],b = M[tp[i+1]];
		if (exist[a][b]) continue;
		prepare(tp[i],tp[i+1]);
		exist[a][b] = exist[b][a] = true;
	}
	printf("%.8f\n",work());
	return 0;
}

Compiler output:
a.cc: In member function 'double Point::angle() const':
a.cc:35:39: error: 'atan2' was not declared in this scope
   35 |         double angle() const { return atan2(y,x); }
      |                                       ^~~~~
a.cc: At global scope:
a.cc:64:1: error: 'vector' does not name a type
   64 | vector <int> G[maxn*maxn];
      | ^~~~~~
a.cc: In function 'void nadd(int, int)':
a.cc:69:41: error: 'G' was not declared in this scope
   69 | inline void nadd(int u,int v) { ++ncnt; G[u].push_back(ncnt); edge[ncnt] = Segment(u,v); }
      |                                         ^
a.cc: In function 'void prepare(const Point&, const Point&)':
a.cc:89:9: error: 'vector' was not declared in this scope
   89 |         vector <Point> vec;
      |         ^~~~~~
a.cc:7:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    6 | #include<cstdlib>
  +++ |+#include <vector>
    7 | using namespace std;
a.cc:89:22: error: expected primary-expression before '>' token
   89 |         vector <Point> vec;
      |                      ^
a.cc:89:24: error: 'vec' was not declared in this scope
   89 |         vector <Point> vec;
      |                        ^~~
a.cc: In function 'double work()':
a.cc:107:43: error: 'G' was not declared in this scope
  107 |         for (int i = 1;i <= cnt;++i) sort(G[i].begin(),G[i].end(),cmpG);
      |                                           ^
a.cc:110:26: error: 'G' was not declared in this scope
  110 |                 int nn = G[i].size();
      |                          ^
a.cc:117:41: error: 'vector' was not declared in this scope
  117 |                         int j = i,p,nn; vector <Point> vec;
      |                                         ^~~~~~
a.cc:117:41: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:117:54: error: expected primary-expression before '>' token
  117 |                         int j = i,p,nn; vector <Point> vec;
      |                                                      ^
a.cc:117:56: error: 'vec' was not declared in this scope
  117 |                         int j = i,p,nn; vector <Point> vec;
      |                                                        ^~~
a.cc:121:54: error: 'G' was not declared in this scope
  121 |                                 p = edge[j].to; nn = G[p].size();
      |                                                      ^