#P3104. [USACO14MAR] Counting Friends G

[USACO14MAR] Counting Friends G

Description

FJ’s N(2N500)N(2 \le N \le 500) 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 N+1N+1 numbers, instead of the expected NN).

Please help FJ determine which numbers could be the erroneous one.

Input Format

Line 1: An integer NN.

Lines 2 to N+2N+2: A total of N+1N+1 integers, each line giving the number of friends of a cow, possibly including the erroneous one.

Output Format

Line 1: An integer KK, the number of values that could be erroneous (if K=0K=0, it means that removing any single number cannot produce a feasible friendship configuration).

Lines 2 to K+1K+1: Each line contains an index in FJ’s list whose number could be the erroneous one. That is, removing that number makes the remaining NN 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 2,2,1,32, 2, 1, 3, which is valid. If we name the four cows A,B,C,DA, B, C, D, then the pairings (A,B),(A,C),(A,D),(B,C)(A,B),(A,C),(A,D),(B,C) satisfy the requirements. Similarly, removing the fourth or fifth number also yields a valid friendship configuration. However, removing a 22 cannot yield a valid configuration. It is easy to see that if a 22 is removed, the sum of the remaining numbers is odd, which clearly cannot form a valid friendship configuration.

Translated by ChatGPT 5