새로 짓는 칸이 이미 지은 칸과 변이나 꼭짓점으로 맞닿고 외부에서 빈 칸만 지나 도달 가능해야 한다는 조건 아래 n개 칸의 건설 순서를 정한다.
어려움8그래프유니온 파인드그리디시뮬레이션아직 제출이 없습니다시간 제한3.5초메모리 제한512 MBWe are going to build a new city: the Metropolis. The city is going to be built on an infinite square grid. The finished city will consist of n skyscrapers, numbered from 1 to n. Each skyscraper will occupy a different cell of the grid. At any moment during the construction, the cells that currently do not contain a skyscraper are called empty.
You are given the planned coordinates of the n skyscrapers. Your task is to find an order in which they can be built while satisfying the rules listed below.
If a solution exists, let’s denote the numbers of skyscrapers in the order in which they should be built by s1, . . . , sn. There are two types of subtasks:
The first line contains a single integer n (1 ≤ n ≤ 150, 000) – the number of skyscrapers.
The second line contains a single integer t (1 ≤ t ≤ 2) describing the type of the subtask as defined above.
Then, n lines follow. The i-th of these lines contains two space-separated integers ri and ci (|ri|, |ci| ≤ 109) denoting the coordinates of the cell containing skyscraper i.
It is guaranteed that no two skyscrapers coincide.
If it is impossible to build the skyscrapers according to the given rules, print a single line containing the string “NO”.
Otherwise, print n + 1 lines. The first of these lines should contain the string “YES”. For each i, the i-th of the remaining n lines should contain a single integer si.
In subtasks with t = 1, if there are multiple valid orders, you may output any one of them.
In the first example, there are three skyscrapers in a row. All of them can always be reached from outside the Metropolis, and there are four build orders which preserve connectivity:
Since t = 2, we must choose the first option.
In the second example, the only difference from the first example is that skyscraper 2 shares only corners with skyscrapers 1 and 3, the same set of orders as in the first sample is valid. Since t = 1, each of these answers is correct.
In the third example, the Metropolis is disconnected. We obviously can’t build that.