#1959. [Baltic2010] Pcb

[Baltic2010] Pcb

题目描述

In a printed circuit board, conductive wires are laid on a non-conductive board. Because the conductors in the same layer cannot cross without creating short-circuits, boards with conductors divided into several layers separated by non-conductive board material are used in more complex cases. However, boards with more layers are more expensive. So, manufacturers try to allocate the required conductors to layers in a way that minimizes the number of layers needed.

In this task we look at boards where each conductor is connecting two ports located on opposite edges of the board and seek to minimize the cost of such a board.

Consider, for example, the board shown on the left on the figure below. If one conductor has to connect AA to BB and another DD to CC, this could be achieved in a single layer, as shown in the middle on the figure. But a conductor connecting AA to CC and another connecting DD to BB could not be laid out in the same layer, as can be seen on the right on the figure.

Write a program that is given the locations of the endpoints of the nn conductors on a w×hw \times h board and determines the minimal number of layers needed to accommodate all of them.

It may be assumed the width of the conductors is very small compared to the distances between the ports. That is, between any two conductors, there is always enough room for a third one.

输入格式

The first line of the text file pcb.in contains nn, the number of connectors. Each of the following nn lines contains two integers, xi1x_{i1} and xi2x_{i2}, separated by a space, meaning that the ii-th conductor has to connect the points (xi1,0)(x_{i1} ,0) and (xi2,h)(x_{i2} , h). It may be assumed that all the 2×n2 \times n endpoints given in the input are distinct.

输出格式

The first and only line of the text file pcb.out should contain a single integer, the minimal number of layers needed to accommodate all the required conductors.

2
1 1
3 3
1
2
1 3
3 1
2

数据规模与约定

For all the test cases,1n1051 \le n \le 10^5,0xij1060 \le x_{ij} \le 10^6.