Hiking in the Hills
Time limit2sMemory limit256 MB
Find a route from camp A to lookout B across the triangulated landscape whose highest point is as low as possible.
- Level
Medium7 of 10
- Topics
- Union-find, Minimum spanning tree, Geometry, Graph
- Solved
- No attempts yet
Problem
Helen is hiking with her friends in a highland. The plan is to walk from their camp A to a lookout B.
Helen has started to feel dizzy from altitude sickness. Help the group find a route whose highest point is as low as possible.
The landscape is given as a set of triangles. A route is a polyline from A to B in which every segment lies entirely inside one of those triangles, so the route never leaves the surface. The topmost height of a route is the largest coordinate of any point on it. Find the smallest topmost height over all routes from A to B.
Input
The landscape covers a square region of size .
The first line contains one integer , the number of triangles in the landscape ().
Each of the next lines contains nine integers , , , , , , , , , the coordinates of one triangle. Every coordinate belongs to the closed interval .
The last two lines contain three integers each: , , and , , , the coordinates of camp A and lookout B.
The triangles describe one consistent continuous landscape. Their projections onto the XY plane are non-degenerate and fill the square without overlapping. A vertex of one triangle never lies inside an edge of another triangle. A and B lie on the landscape surface and are different points.
Output
Print one integer, the smallest topmost height that a route from A to B can have.