Language: C++

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

const int N = 110;

const double eps = 1e-8;

struct Point {
	double x, y;
	Point() {}
	Point(double x, double y): x(x), y(y) {}
	void read() {
		scanf("%lf %lf", &x, &y);
	}
	void print() const {
		printf("%.10f %.10f\n", x, y);
	}
}p[N];

const int V = N * N;
const int E = N * N * N;

int n, total;

Point operator + (const Point & a, const Point & b) {
	return Point(a.x + b.x, a.y + b.y);
}

Point operator - (const Point & a, const Point & b) {
	return Point(a.x - b.x, a.y - b.y);
}

Point operator * (const Point & a, double p) {
	return Point(a.x * p, a.y * p);
}

Point operator / (const Point & a, double p) {
	return Point(a.x / p, a.y / p);
}

double Cross(const Point & a, const Point & b) {
	return a.x * b.y - a.y * b.x;
}

double Dot(const Point & a, const Point & b) {
	return a.x * b.x + a.y * b.y;
}

double Len(const Point & a) {
	return sqrt(a.x * a.x + a.y * a.y);
}

double Angle(const Point & a) {
	return atan2(a.y, a.x);
}

int dcmp(double x) {
	if (fabs(x) < eps) return 0;
	return x > 0 ? 1 : -1;
}

bool operator < (const Point & a, const Point & b) {
	int f = dcmp(a.x - b.x);
	if (f) return f < 0;
	f = dcmp(a.y - b.y);
	return f < 0;
}

bool operator == (const Point & a, const Point & b) {
	return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}

Point Get(const Point & P, const Point & A, const Point & Q, const Point & B) {
	Point v = A - P;
	Point w = B - Q;
	Point u = P - Q;
	double t = Cross(w, u) / Cross(v, w);
	return P + v * t;
}

int On(const Point & a, const Point & b, const Point & c) {
	return dcmp(Cross(b - a, b - c)) == 0 && dcmp(Dot(b - a, b - c)) <= 0;
}

int inter(const Point & a, const Point & b, const Point & c, const Point & d) {
	return dcmp(Cross(b - a, c - a)) * dcmp(Cross(b - a, d - a)) < 0 && dcmp(Cross(a - c, d - c)) * dcmp(Cross(b - c, d - c)) < 0;
}

int cnt, last[V], e[E], nxt[E], to[E], vis[E];
vector<Point> pts;
set<pair<int, int> > S;

void add(int x, int y) {
	S.insert(make_pair(x, y));
	e[++total] = y;
	nxt[total] = last[x];
	last[x] = total;
}


int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		p[i].read();
		pts.push_back(p[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j + 1 < n; j++) {
			if (inter(p[i], p[i + 1], p[j], p[j + 1])) {
				pts.push_back(Get(p[i], p[i + 1], p[j], p[j + 1]));
			}
		}
	}
	sort(pts.begin(), pts.end());
	pts.erase(unique(pts.begin(), pts.end()), pts.end());
	total = -1;
	for (int i = 0; i < n; i++) last[i] = -1;
	for (int i = 0; i < n - 1; i++) {
		vector<pair<double, int> > v;
		for (int j = 0; j < (int) pts.size(); j++) {
			if (On(p[i], pts[j], p[i + 1])) {
				v.push_back(make_pair(Len(pts[j] - p[i]), j));
			}
		}
		sort(v.begin(), v.end());
		for (int j = 0; j + 1 < (int) v.size(); j++) {
			int x = v[j].second, y = v[j + 1].second;
			if (S.find(make_pair(x, y)) != S.end()) continue;
			add(x, y);
			add(y, x);
		}
	}
	for (int x = 0; x < (int) pts.size(); x++) {
		vector<pair<double, int> > v;
		for (int i = last[x]; i >= 0; i = nxt[i]) {
			int y = e[i];
			v.push_back(make_pair(Angle(pts[y] - pts[x]), i));
		}
		sort(v.begin(), v.end());
		for (int i = 0; i < (int) v.size(); i++) {
			to[v[(i + 1) % (int) v.size()].second ^ 1] = v[i].second;
		}
	}
	double ans = 0;
	for (int i = 0; i <= total; i++) {
		if (!vis[i]) {
			double t = 0;
			int u = i;
			for (; !vis[u]; u = to[u]) {
				vis[u] = 1;
				t += Cross(pts[e[u ^ 1]], pts[e[u]]);
			}
			if (u == i && t > 0) {
				ans += t;
			}
		}
	}
	printf("%.15f\n", ans * 0.5);
	return 0;
}

Compiler output:
a.cc:94:1: error: 'vector' does not name a type
   94 | vector<Point> pts;
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:109:17: error: 'pts' was not declared in this scope; did you mean 'puts'?
  109 |                 pts.push_back(p[i]);
      |                 ^~~
      |                 puts
a.cc:114:33: error: 'pts' was not declared in this scope; did you mean 'puts'?
  114 |                                 pts.push_back(Get(p[i], p[i + 1], p[j], p[j + 1]));
      |                                 ^~~
      |                                 puts
a.cc:118:14: error: 'pts' was not declared in this scope; did you mean 'puts'?
  118 |         sort(pts.begin(), pts.end());
      |              ^~~
      |              puts
a.cc:123:17: error: 'vector' was not declared in this scope
  123 |                 vector<pair<double, int> > v;
      |                 ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include <set>
  +++ |+#include <vector>
    5 | 
a.cc:123:42: error: expected primary-expression before '>' token
  123 |                 vector<pair<double, int> > v;
      |                                          ^
a.cc:123:44: error: 'v' was not declared in this scope
  123 |                 vector<pair<double, int> > v;
      |                                            ^
a.cc:132:49: error: 'y' was not declared in this scope
  132 |                         if (S.find(make_pair(x, y)) != S.end()) continue;
      |                                                 ^
a.cc:133:32: error: 'y' was not declared in this scope
  133 |                         add(x, y);
      |                                ^
a.cc:138:17: error: 'vector' was not declared in this scope
  138 |                 vector<pair<double, int> > v;
      |                 ^~~~~~
a.cc:138:17: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:138:42: error: expected primary-expression before '>' token
  138 |                 vector<pair<double, int> > v;
      |                                          ^
a.cc:138:44: error: 'v' was not declared in this scope
  138 |                 vector<pair<double, int> > v;
      |                                            ^