CF566E.Restoring Map

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Archaeologists found some information about an ancient land of Treeland. We know for sure that the Treeland consisted of n cities connected by the n - 1 road, such that you can get from each city to any other one along the roads. However, the information about the specific design of roads in Treeland has been lost. The only thing that the archaeologists can use is the preserved information about near cities.

Two cities of Treeland were called near, if it were possible to move from one city to the other one by moving through at most two roads. Also, a city is considered near to itself. During the recent excavations archaeologists found a set of n notes, each of them represents a list of cities, near to some of the n cities of the country. However, unfortunately, none of the found records lets you understand in what order the cities go in the list and for which city in the list the near to it cities were listed.

Help the archaeologists and restore any variant of the map of Treeland that meets the found information.

考古学家发现了一些关于远古国度“树国”(Treeland)的信息。我们确知树国由 nn 座城市组成,这些城市通过 n−1n-1 条道路相连,且任意两座城市之间均可通过道路相互到达(即该图是一棵树)。然而,关于树国中道路具体连接方式的信息已经遗失。考古学家目前唯一可利用的线索,是有关“邻近城市”的保存记录。

在树国中,若两座城市之间可通过至多两条道路相互到达,则称这两座城市为邻近的;此外,每座城市自身也被视为与自身邻近。在最近的发掘中,考古学家找到了 nn 条记录,每条记录对应树国中某一座城市的邻近城市列表。但不幸的是,所有这些记录均未标明:(1)列表中各城市出现的顺序;(2)该列表究竟对应哪一座城市。

请帮助考古学家还原出任意一张满足上述记录信息的树国地图。

输入格式

The first line contains integer n (2 ≤ n ≤ 1000) — the number of cities in the country.

Next n lines describe the found lists of near cities. Each list starts from number k (1 ≤ k ≤ n), representing the number of cities in the list followed by k city numbers. All numbers in each list are distinct.

It is guaranteed that the given information determines at least one possible road map.

第一行包含一个整数 nn(2≤n≤10002 \leq n \leq 1000)—— 表示该国的城市数量。

接下来的 nn 行描述了所发现的各城市邻近城市列表。每行列表以一个数字 kk(1≤k≤n1 \leq k \leq n)开头,表示该列表中城市的数量,随后是 kk 个城市编号。每个列表中的所有数字互不相同。

保证所给信息至少能确定一张可能的道路地图。

输出格式

Print n - 1 pairs of numbers representing the roads of the country. The i-th line must contain two integers a__i, b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i), showing that there is a road between cities a__i and b__i.

The answer you print must satisfy the description of close cities from the input. You may print the roads of the countries in any order. The cities that are connected by a road may also be printed in any order.

If there are multiple good answers, you may print any of them.

输出表示该国道路的 n−1n-1 对数字。第 ii 行必须包含两个整数 ai, bia_i,\,b_i(1≤ai, bi≤n1 \le a_i,\,b_i \le n,且 ai≠bia_i \ne b_i),表示城市 aia_i 与城市 bib_i 之间存在一条道路。

您所输出的答案必须满足输入中关于“邻近城市”的描述。您可以按任意顺序输出这些道路;每条道路所连接的两座城市也可按任意顺序输出。

若存在多个合法答案,您可输出其中任意一个。

输入输出样例

  • 输入#1

    5
    4 3 2 4 1
    5 5 3 2 4 1
    5 4 2 1 5 3
    4 2 1 4 3
    3 1 4 5

    输出#1

    1 4
    1 2
    1 3
    4 5
  • 输入#2

    6
    5 6 1 3 4 2
    5 2 1 3 4 6
    6 3 6 2 5 4 1
    6 6 1 2 5 3 4
    3 5 2 4
    5 3 1 2 4 6

    输出#2

    2 4
    1 2
    2 3
    2 6
    4 5

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

首页