PCB
시간 제한1초메모리 제한2048 MB
왼쪽 변의 전원 n개와 내부의 소비자 n개를 서로 교차하지 않는 L자 전선으로 연결해 전체 전선 길이의 합을 최소로 만든다.
문제
In designing a printed circuit board (PCB), each consumer must be connected to a power supply via conductive wires. The PCB is a rectangle of width and height . It is represented as a grid of integer coordinates from to .
There are power supplies along the left edge of the board and consumers each located somewhere inside the board. The th power supply is located at position and the th consumer is located at position . Each power supply must connect to exactly one consumer and vice versa.
Each wire must run along the grid lines, bending at most once. i.e., each wire is either a straight vertical or horizontal line or makes exactly one -degree turn, forming an "L" shape. Wires cannot cross or overlap with each other anywhere along their paths.
Your task is to determine a matching between power supplies and consumers such that the total length of all wires is minimized.
입력
The input consists of several lines:
- The first line contains three integers , and (; ).
- Each of the next lines contains an integer ().
- Each of the next lines contains two integers and (; ).
It is guaranteed that each point in the board contains at most one power supply or consumer. Moreover, no two consumers and exist where .
출력
If it is not possible to find such a matching under the given constraints, output a single line containing .
Otherwise, output a single line containing space-separated integers. The th integer describes , indicating that power supply is connected to consumer .