A12365 | New Year and the Acquaintance Estimation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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](https://en.wikipedia.org/wiki/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.
This morning, somebody anonymously sent Bob the following link: [graph realization problem](https://en.wikipedia.org/wiki/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.
输入格式
The first line contains one integer $n$ ( $1 \leq n \leq 5 \cdot 10^5$ ), the number of people on the network excluding Bob.
The second line contains $n$ numbers $a_1,a_2, \dots, a_n$ ( $0 \leq a_i \leq n$ ), with $a_i$ being the number of people that person $i$ is a friend of.
The second line contains $n$ numbers $a_1,a_2, \dots, a_n$ ( $0 \leq a_i \leq n$ ), with $a_i$ being the number of people that person $i$ is a friend of.
输出格式
Print all possible values of $a_{n+1}$ — the amount of people that Bob can be friend of, in increasing order.
If no solution exists, output $-1$ .
If no solution exists, output $-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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted