Language: C++

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

constexpr double EPS = 1e-9;

struct point {
	double x, y;
	explicit point(double x_ = 0.0, double y_ = 0.0):x(x_), y(y_) {}
	point(const point &p):x(p.x), y(p.y) {}

	point operator+(const point &p) const {
		return point(x + p.x, y + p.y);
	}

	point operator-(const point &p) const {
		return point(x - p.x, y - p.y);
	}

	point operator*(double s) const {
		return point(x * s, y * s);
	}

	point operator*(const point &p) const {
		return point(x * p.x - y * p.y, x * p.y + y * p.x);
	}

	point operator/(double s) const {
		return point(x / s, y / s);
	}

	bool operator<(const point &p) const {
		return x + EPS < p.x || (abs(x - p.x) < EPS && y + EPS < p.y);
	}

	bool operator==(const point &p) const {
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
};

double norm(const point &p) {
	return p.x * p.x + p.y * p.y;
}

double abs(const point &p) {
	return sqrt(norm(p));
}

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

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

struct line {
	point a, b;
	line(const point &a_, const point &b_):a(a_), b(b_){}
};

struct segment {
	point a, b;
	segment(const point &a_, const point &b_):a(a_), b(b_){}
};

typedef vector<point> polygon;

int ccw(const point &a, point b, point c) {
	b = b - a;
	c = c - a;
	const double tmp = cross(b, c);
	if(tmp > EPS) return 1; // ccw
	if(tmp < -EPS) return -1; // cw
	if(dot(b, c) < 0) return 2; // c, a, b 順に一直線上
	if(norm(b) < norm(c)) return -2; // a, b, c 順に一直線上
	return 0; //a, c, b 順で一直線上
}

bool intersect(const segment &s, const segment &t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0
		&& ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

double dist(const line &l, const point &p) {
	return abs(cross(l.b - l.a, p - l.a)) / abs(l.b - l.a);
}

double dist(const segment &s, const point &p) {
	if(dot(s.b - s.a, p - s.a) < 0) return abs(p - s.a);
	if(dot(s.a - s.b, p - s.b) < 0) return abs(p - s.b);
	return dist(line(s.a, s.b), p);
}

double dist(const segment &s, const segment &t) {
	if(intersect(s, t)) return 0;
	return min({dist(s, t.a), dist(s, t.b), dist(t, s.a), dist(t, s.b)});
}

double dist(const polygon &P1, const polygon &P2) {
	double res = INT_MAX;

	point p1 = P1.back();
	for(const auto &c1 : P1) {
		const segment s1(c1, p1);

		point p2 = P2.back();

		for(const auto &c2 : P2) {
			const segment s2(c2, p2);
			chmin(res, dist(s1, s2));
			p2 = c2;
		}

		p1 = c1;
	}

	return res;
}

double dijkstra(int s, int g, const vector<vector<double>> &mat) {
	const int n = mat.size();

	vector<double> dist(n, INT_MAX);
	vector<bool> used(n, false);

	dist[s] = 0.0;

	for(int iter = 0; iter < n; ++iter) {
		int v = -1;

		for(int u = 0; u < n; ++u) {
			if(!used[u] && (v == -1 || dist[v] > dist[u] + EPS)) {
				v = u;
			}
		}

		if(v == g) return dist[g];

		used[v] = true;

		for(int to = 0; to < n; ++to) {
			chmin(dist[to], dist[v] + mat[v][to]);
		}
	}
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	constexpr int MAX_Y = 10000;

	for(int w, n; cin >> w >> n && w;) {
		const int V = n + 2;

		vector<polygon> pillars;
		pillars.reserve(V);
		pillars.emplace_back(polygon{point(-1, 0), point(-1, MAX_Y), point(0, MAX_Y), point(0, 0)});
		pillars.emplace_back(polygon{point(w, 0), point(w, MAX_Y), point(w + 1, MAX_Y), point(w + 1, 0)});

		for(int i = 0; i < n; ++i) {
			int m;
			cin >> m;

			polygon P;
			P.reserve(m);

			for(int j = 0; j < m; ++j) {
				int x, y;
				cin >> x >> y;
				P.emplace_back(x, y);
			}

			pillars.emplace_back(move(P));
		}

		vector<vector<double>> mat(V, vector<double>(V));

		for(int v = 0; v < V; ++v) {
			mat[v][v] = 0.0;

			for(int u = v + 1; u < V; ++u) {
				mat[v][u] = mat[u][v] = dist(pillars[v], pillars[u]);
			}
		}

		cout << dijkstra(0, 1, mat) << endl;
	}

	return EXIT_SUCCESS;
}

Compiler output:
a.cc: In function 'double dist(const segment&, const segment&)':
a.cc:101:19: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
  101 |         return min({dist(s, t.a), dist(s, t.b), dist(t, s.a), dist(t, s.b)});
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
a.cc: In function 'double dist(const polygon&, const polygon&)':
a.cc:105:22: error: 'INT_MAX' was not declared in this scope
  105 |         double res = INT_MAX;
      |                      ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include <vector>
  +++ |+#include <climits>
    5 | using namespace std;
a.cc: In function 'double dijkstra(int, int, const std::vector<std::vector<double> >&)':
a.cc:128:32: error: 'INT_MAX' was not declared in this scope
  128 |         vector<double> dist(n, INT_MAX);
      |                                ^~~~~~~
a.cc:128:32: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:150:1: warning: control reaches end of non-void function [-Wreturn-type]
  150 | }
      | ^