Ex - Don't Swim Editorial by spheniscine


Consider the convex hull of the \(N+2\) points that include \(S\), \(T\), and the vertices of \(C\). This can be found using e.g. Graham scan in \(O(N \log N)\).

If \(S\) and \(T\) are both vertices of the resulting convex hull, the shortest path between them is one of the two paths along that convex hull, so pick the minimum between them.

Otherwise, consider the shape formed by removing \(C\) and its interior from that convex hull. One of \(S\) or \(T\) is a vertex of the resulting polygon, and the other is in the interior or an edge of that shape. (It can be seen that if this were not so, both must be part of the convex hull.) Therefore there is a direct path between them that doesn’t cross \(C\), so we just answer with the Euclidean distance between them.

posted:
last update: