CF1578K.Kingdom of Islands
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The Kingdom of Islands consists of p islands. As the king, you rule over the whole kingdom, while each island is ruled over by one or several jarls under your rule. In total, there are n jarls under your jurisdiction.
Each island of the kingdom has its own strong traditions, so jarls that rule over the same island support each other and never have conflicts. The downsides of such strength are cultural conflicts between people inhabiting different islands. Thus, two jarls that rule over different islands are in conflict.
However, recent years brought a few changes to traditional relations between the jarls. To your knowledge, there are exactly k pairs of jarls such that relationships between two jarls in the pair are different from the traditional. That is, if two jarls of the pair you know rule over the same island, these jarls are in conflict. If they rule over different islands, then they overcome cultural disagreement and there is no conflict between them anymore.
As a true responsible king, you are worried about whether the kingdom is close to a major conflict. In order to estimate the current situation, you would like to find the largest possible group of jarls such that every two jarls in the group are in conflict.
岛屿王国由 p 座岛屿组成。作为国王,您统治着整个王国,而每座岛屿则由一位或多位伯爵(jarl)在您的统治下进行治理。总计,您管辖范围内共有 n 位伯爵。
王国中的每座岛屿都拥有各自深厚的传统:统治同一座岛屿的伯爵彼此支持,从不发生冲突。然而,这种团结的弊端在于不同岛屿居民之间存在文化冲突。因此,统治不同岛屿的两位伯爵必然相互敌对。
然而,近年来伯爵之间的传统关系发生了一些变化。据您所知,恰好存在 k 对伯爵,其相互关系与传统情形相反:若某一对中两位伯爵统治同一座岛屿,则他们彼此敌对;若他们统治不同岛屿,则他们克服了文化分歧,彼此不再敌对。
作为一名真正负有责任的国王,您担忧王国是否正濒临一场重大冲突。为评估当前局势,您希望找出一个尽可能大的伯爵集合,使得该集合中任意两位伯爵均相互敌对。
输入格式
The first line of the input consists of two integers p and n (1≤p≤n≤105; 1≤p≤104).
The second line consists of n integers s1,s2,…,sn (1≤si≤p). The integer si denotes that the i-th jarl rules over the island number si. It is guaranteed that each island is ruled by at least one jarl.
The third line consists of a single integer k (0≤k≤20).
Then k lines follow. The j-th of these lines consists of two distinct integers aj and bj (1≤aj<bj≤n), denoting that the relation between the aj-th jarl and the bj-th jarl differs from traditional. It is guaranteed that no pair of jarls appears twice in this list.
输入的第一行包含两个整数 p 和 n(1≤p≤n≤105;1≤p≤104)。
第二行包含 n 个整数 s1,s2,…,sn(1≤si≤p)。整数 si 表示第 i 位雅尔(jarl)统治着编号为 si 的岛屿。保证每个岛屿至少被一位雅尔统治。
第三行包含一个整数 k(0≤k≤20)。
接下来是 k 行。其中第 j 行包含两个互异的整数 aj 和 bj(1≤aj<bj≤n),表示第 aj 位雅尔与第 bj 位雅尔之间的关系不同于传统关系。保证该列表中不会出现重复的雅尔对。
输出格式
In the first line print a single integer q between 1 and n — the largest possible number of jarls in a pairwise conflicting group. In the second line print q distinct integers between 1 and n — the numbers of jarls in the group. The numbers of jarls can be printed in any order.
第一行输出一个介于 1 和 n 之间的整数 q —— 即两两互斥的伯爵组所能包含的最大伯爵人数。
第二行输出 q 个互不相同的、介于 1 和 n 之间的整数 —— 即该组中各位伯爵的编号。伯爵编号的输出顺序可以任意。
输入输出样例
输入#1
4 4 1 2 3 4 1 2 3
输出#1
3 1 4 2
输入#2
2 4 1 1 2 2 1 3 4
输出#2
3 2 4 3
输入#3
4 8 1 1 1 2 2 3 4 4 7 1 2 2 3 3 6 4 5 5 7 2 7 3 8
输出#3
6 8 6 5 4 2 1
说明/提示
The conflict graph for the last sample testcase is given below. Each circle represents an island.

最后一个样例测试用例的冲突图如下所示。每个圆圈代表一个岛屿。

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