CF1045E.Ancient civilizations

NOI/NOI+/CTSC

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

On the surface of a newly discovered planet, which we model by a plane, explorers found remains of two different civilizations in various locations. They would like to learn more about those civilizations and to explore the area they need to build roads between some of locations. But as always, there are some restrictions:

  1. Every two locations of the same civilization are connected by a unique path of roads
  2. No two locations from different civilizations may have road between them (explorers don't want to accidentally mix civilizations they are currently exploring)
  3. Roads must be straight line segments
  4. Since intersections are expensive to build, they don't want any two roads to intersect (that is, only common point for any two roads may be at some of locations)

Obviously all locations are different points in the plane, but explorers found out one more interesting information that may help you – no three locations lie on the same line!

Help explorers and find a solution for their problem, or report it is impossible.

在一个新发现的行星表面(我们将其建模为一个平面)上,探险家们在不同位置发现了两个不同文明的遗迹。他们希望进一步了解这些文明,并为此需要在某些位置之间修建道路以开展探索。但正如往常一样,存在一些限制条件:

  1. 同一文明的任意两个位置之间必须由一条唯一的道路路径连接;
  2. 不同文明的位置之间不得修建道路(探险家们不希望意外混淆当前正在探索的两个文明);
  3. 道路必须是直线段;
  4. 由于建造道路交叉口成本高昂,他们不希望任意两条道路相交(即:任意两条道路的唯一公共点(若存在)只能是某个位置点)。

显然,所有位置均为平面上互异的点;但探险家们还发现了一个更有用的信息——任意三点均不共线!

请帮助探险家们求解该问题,或判定其无解。

输入格式

In the first line, integer nn (1≤n≤103)(1 \leq n \leq 10^3) - the number of locations discovered.

In next nn lines, three integers x,y,cx, y, c (0≤x,y≤104,c∈0,1)(0 \leq x, y \leq 10^4, c \in {0, 1}) - coordinates of the location and number of civilization it belongs to.

第一行包含一个整数 nn(1≤n≤1031 \leq n \leq 10^3),表示已发现的位置数量。

接下来的 nn 行中,每行包含三个整数 x,y,cx, y, c(0≤x,y≤1040 \leq x, y \leq 10^4,c∈{0,1}c \in \{0, 1\}),分别表示该位置的坐标及其所属文明的编号。

输出格式

In first line print number of roads that should be built.

In the following lines print all pairs of locations (their 00-based indices) that should be connected with a road.

If it is not possible to build roads such that all restrictions are met, print "Impossible". You should not print the quotation marks.

第一行输出需要修建的道路数量。

接下来的每一行输出一对需要通过道路连接的位置(使用从 00 开始的索引)。

如果无法修建道路以满足所有限制条件,则输出 "Impossible"(不输出引号)。

输入输出样例

  • 输入#1

    5
    0 0 1
    1 0 0
    0 1 0
    1 1 1
    3 2 0

    输出#1

    3
    1 4
    4 2
    3 0

输入解题思路,AI测评打分。不知道怎么写?

首页