#P3104. [USACO14MAR] Counting Friends G
[USACO14MAR] Counting Friends G
Description
FJ’s cows have joined the social network "Cowbook".
Each cow has one or more friends on Cowbook, so FJ made a list of each cow’s number of friends. During this process, however, he mistakenly included one extra number in the list (so the final list contains numbers, instead of the expected ).
Please help FJ determine which numbers could be the erroneous one.
Input Format
Line 1: An integer .
Lines 2 to : A total of integers, each line giving the number of friends of a cow, possibly including the erroneous one.
Output Format
Line 1: An integer , the number of values that could be erroneous (if , it means that removing any single number cannot produce a feasible friendship configuration).
Lines 2 to : Each line contains an index in FJ’s list whose number could be the erroneous one. That is, removing that number makes the remaining numbers form a valid set of friendships. Output the indices in increasing order.
4
1
2
2
1
3
3
1
4
5
Hint
Sample explanation:
FJ has four cows. Two of them have one friend, two have two friends, and one has three friends (of course, one of these numbers is wrong and should not be on the list).
If we remove the first number in FJ’s list, the remaining sequence is , which is valid. If we name the four cows , then the pairings satisfy the requirements. Similarly, removing the fourth or fifth number also yields a valid friendship configuration. However, removing a cannot yield a valid configuration. It is easy to see that if a is removed, the sum of the remaining numbers is odd, which clearly cannot form a valid friendship configuration.
Translated by ChatGPT 5
京公网安备 11011102002149号