Language: C++

#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;


int gcd(int a, int b)
{
	if(a < b) swap(a, b);
	if(b == 0) return a;
	return gcd(b, a % b);
}

pair<int, int> pt_minus(pair<int,int> a, pair<int,int> b)
{
	return {a.first - b.first, a.second - b.second};
}

bool on_line(pair<int,int> l1, pair<int,int> l2, pair<int,int> p)
{
	if(max(l1.first, l2.first) < p.first || min(l1.first, l2.first) > p.first)
		return false;
	if(max(l1.second, l2.second) < p.second || min(l1.second, l2.second) > p.second)
		return false;

	pair<int,int> d1 = pt_minus(l2, l1);
	pair<int,int> d2 = pt_minus(p, l1);
	int g1 = gcd(d1.first, d1.second);
	int g2 = gcd(d2.first, d2.second);
	d1.first /= g1; d1.second /= g1;
	d2.first /= g2; d2.second /= g2;

	return d1 == d2;
}

double calc_dist(pair<double,double> p, pair<double,double> q)
{
	double dx = p.first - q.first;
	double dy = p.second - q.second;
	return sqrt(dx * dx + dy * dy);
}

pair<double, double> calc_pos(vector<pair<int, int> > &pos, pair<int, int> ct, int vt, int dir, double t)
{
	int next = -1;
	const int n = pos.size();

	for(int i = 0; i < n - 1; ++i) {
		if(on_line(pos[i], pos[i + 1], ct)) {
			next = i + dir;
			break;
		}
	}

	assert(next != -1);

	double sum_dist = 0;

	for(int v = next; v >= 0 && v < (int)pos.size(); v += dir * 2 - 1) {

		double d = calc_dist(ct, pos[v]);

		if(sum_dist + d < t * vt) {
			sum_dist += d;
			ct = pos[v];
			continue;
		}

		double dx = pos[v].first - ct.first;
		double dy = pos[v].second - ct.second;
		double r = (t * vt - sum_dist) / d;
		return {ct.first + dx * r, ct.second + dy * r};
	}

	return ct;
}

double calc_half_time(vector<pair<int, int> > &pos, pair<int, int> ct, int vt, int dir, pair<double, double> cp, int vp, double margin)
{
	double lb = 0, ub = 1e10;
	int max_step = 100;

	for(int step = 0; step < max_step; ++step) {

		double mid = (lb + ub) / 2;
		pair<double,double> p = calc_pos(pos, ct, vt, dir, mid + margin);

		if(calc_dist(cp, p) > vp * mid)
			lb = mid;
		else
			ub = mid;
	}

	return (lb + ub) / 2;
}

double calc_stop_time(vector<pair<int, int> > &pos, pair<int, int> ct, int vt, int dir)
{
	pair<double,double> last = calc_pos(pos, ct, vt, dir, 1e10);
	double lb = 0, ub = 1e10;
	int max_step = 100;

	for(int step = 0; step < max_step; ++step) {
		double mid = (lb + ub) / 2;
		if(calc_pos(pos, ct, vt, dir, mid) == last)
			ub = mid;
		else
			lb = mid;
	}

	return (lb + ub) / 2;
}

double calc_time(vector<pair<int, int> > &pos, pair<int, int> ct, int vt, int dir, pair<int, int> cp, int vp)
{
	double lr1 = calc_half_time(pos, ct, vt, 0, cp, vp, 0.0);
	double lr2 = calc_half_time(pos, ct, vt, 1, calc_pos(pos, ct, vt, 0, lr1), vp, lr1);

	double rl1 = calc_half_time(pos, ct, vt, 1, cp, vp, 0.0);
	double rl2 = calc_half_time(pos, ct, vt, 0, calc_pos(pos, ct, vt, 1, rl1), vp, rl1);

	double ls = calc_stop_time(pos, ct, vt, 0);
	double rs = calc_stop_time(pos, ct, vt, 1);

	double a1 = min(lr1 + lr2, max(lr1, rs));
	double a2 = min(rl1 + rl2, max(rl1, ls));
	double a3 = max(ls, rs);

	return min({a1, a2, a3});
}


int main()
{
	int n;
	vector<pair<int, int> > pos;
	pair<int, int> ct, cp;
	int vt, vp;

	scanf("%d", &n);
	pos.resize(n);
	for(int i = 0; i < n; ++i)
		scanf("%d%d", &pos[i].first, &pos[i].second);
	scanf("%d%d%d", &ct.first, &ct.second, &vt);
	scanf("%d%d%d", &cp.first, &cp.second, &vp);

	double ans = calc_time(pos, ct, vt, 0, cp, vp);

	printf("%.10f\n", ans);

	return 0;
}

Compiler output:
a.cc: In function 'double calc_dist(std::pair<double, double>, std::pair<double, double>)':
a.cc:46:16: error: 'sqrt' was not declared in this scope
   46 |         return sqrt(dx * dx + dy * dy);
      |                ^~~~