CF1091E.New Year and the Acquaintance Estimation
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if a is a friend of b, then b is also a friend of a. Each user thus has a non-negative amount of friends.
This morning, somebody anonymously sent Bob the following link: graph realization problem and Bob wants to know who that was. In order to do that, he first needs to know how the social network looks like. He investigated the profile of every other person on the network and noted down the number of his friends. However, he neglected to note down the number of his friends. Help him find out how many friends he has. Since there may be many possible answers, print all of them.
鲍勃是社交网络 Faithbug 的活跃用户。在该网络中,用户之间可以建立双向友谊关系。也就是说,如果 a 是 b 的朋友,那么 b 也是 a 的朋友。因此,每位用户的朋友们的数量均为一个非负整数。
今天早上,有人匿名给鲍勃发送了如下链接:图的可实现性问题,鲍勃想知道此人是谁。为此,他首先需要弄清该社交网络的结构。他调查了网络上所有其他用户的个人资料,并记录下了每个人的朋友们的数量。但他却忘记记录下自己拥有的朋友数量。请帮助他推断出他可能有多少个朋友。由于可能存在多个可行的答案,请输出所有可能的结果。
输入格式
The first line contains one integer n (1≤n≤5⋅105), the number of people on the network excluding Bob.
The second line contains n numbers a1,a2,…,an (0≤ai≤n), with ai being the number of people that person i is a friend of.
第一行包含一个整数 n(1≤n≤5⋅105),表示社交网络中除 Bob 外的人数。
第二行包含 n 个数字 a1,a2,…,an(0≤ai≤n),其中 ai 表示第 i 个人的朋友数量。
输出格式
Print all possible values of an+1 — the amount of people that Bob can be friend of, in increasing order.
If no solution exists, output −1.
输出所有可能的 an+1 的值(即 Bob 可以结交的朋友人数),按升序排列。
若不存在解,则输出 −1。
输入输出样例
输入#1
3 3 3 3
输出#1
3
输入#2
4 1 1 1 1
输出#2
0 2 4
输入#3
2 0 2
输出#3
-1
输入#4
35 21 26 18 4 28 2 15 13 16 25 6 32 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22
输出#4
13 15 17 19 21
说明/提示
In the first test case, the only solution is that everyone is friends with everyone. That is why Bob should have 3 friends.
In the second test case, there are three possible solutions (apart from symmetries):
- a is friend of b, c is friend of d, and Bob has no friends, or
- a is a friend of b and both c and d are friends with Bob, or
- Bob is friends of everyone.
The third case is impossible to solve, as the second person needs to be a friend with everybody, but the first one is a complete stranger.
在第一个测试用例中,唯一的解是所有人彼此都是朋友。因此 Bob 应该有 3 个朋友。
在第二个测试用例中,存在三种可能的解(不考虑对称性):
- a 与 b 是朋友,c 与 d 是朋友,而 Bob 没有任何朋友;或
- a 与 b 是朋友,且 c 和 d 均与 Bob 是朋友;或
- Bob 与所有人都是朋友。
第三个测试用例无解,因为第二个人需要与所有人都是朋友,但第一个人却与所有人都毫无关系(完全陌生)。
输入解题思路,AI测评打分。不知道怎么写?