This page is still under construction.

Parts of this page are still being built. What you see may change.

Navigation

Interview

Time limit1sMemory limit1024 MB

Summary
Given N routes that pass through ordered intermediate points, find the route number with the smallest total Manhattan distance from start to end.
Level

Easy2 of 10

Topics
Implementation, Array
Solved
No attempts yet

Problem

Unmatched technology in location-based services

Hyundai AutoEver's navigation software delivers safe and convenient travel. It is used in more than 70 countries and leads the global infotainment market.

Its navigation software offers a wide range of content and services, giving customers a richer mobility experience and new value.

Built on GIS and LBS technology, precise map data, and route search algorithms, its advanced navigation solutions help automakers expand overseas and lead the global market.

Customer first

Vehicle navigation

Hyundai AutoEver helps customers around the world drive to their destinations quickly and safely. Putting customers first is its core value.

Based on center communication, the system tracks the user's current position in real time and provides road traffic conditions, closed sections, and other information that affects traffic flow.

ICPC Sinchon was asked by Hyundai AutoEver to test vehicle navigation. The staff compared the performance of Hyundai AutoEver's OEM navigation with the other N−1N-1 navigation systems from other companies. They confirmed that the OEM navigation finds a more efficient optimal route to the destination.

The team plans to send this experimental data to Hyundai AutoEver after SUAPC 2022 Summer ends. The data contains the following information.

  • The start point (s_x,s_y)(s\_x, s\_y) and the end point (e_x,e_y)(e\_x, e\_y)
  • For each navigation, the intermediate points that must be visited in order to go from (s_x,s_y)(s\_x, s\_y) to (e_x,e_y)(e\_x, e\_y)

The distance between two points is the Manhattan distance. That is, the distance between (a,b)(a,b) and (c,d)(c,d) is ∣a−c∣+∣b−d∣|a-c|+|b-d|. The optimal route distances computed by the navigation systems are all different.

However, on the day of SUAPC 2022 Summer, a sudden computer failure mixed up the experimental values of the navigation systems. Before the contest ends, you are given the data for each navigation. Find which data belongs to the OEM navigation.

Input

The first line contains a positive integer NN, the number of navigation systems used in the experiment. (2≤N≤1 0002 \le N \le 1\,000)

The second line contains four integers s_xs\_x, s_ys\_y, e_xe\_x, e_ye\_y, separated by spaces, which are the coordinates of the start point and the end point. (−109≤s_x,s_y,e_x,e_y≤109-10^9 \le s\_x, s\_y, e\_x, e\_y \le 10^9)

The following lines give the data for navigation 1 through navigation NN, in order. The input for each navigation is as follows.

  • The first line contains M_iM\_i, the number of intermediate points that must be visited in order. (1≤M_i≤1001 \le M\_i \le 100)
  • The next M_iM\_i lines each contain two integers separated by a space, the xx and yy coordinates of the jj-th intermediate point (x_i,j,y_i,j)(x\_{i,j}, y\_{i,j}). (−109≤x_i,j,y_i,j≤109-10^9 \le x\_{i,j}, y\_{i,j} \le 10^9)

Output

Print the number of the data set that belongs to the OEM navigation.

Examples1

  1. Example 1

    Input
    3
    0 0 10 10
    2
    11 1
    9 9
    2
    1 12
    9 9
    2
    5 5
    9 9
    
    Expected output
    3