atcoder#NOMURA2020D. Urban Planning
Urban Planning
Score : points
Problem Statement
There are towns numbered .
Some roads are planned to be built so that each of them connects two distinct towns bidirectionally. Currently, there are no roads connecting towns.
In the planning of construction, each town chooses one town different from itself and requests the following: roads are built so that the chosen town is reachable from itself using one or more roads.
These requests from the towns are represented by an array . If , it means that Town has not chosen the request; if , it means that Town has chosen Town .
Let be the number of towns such that . There are ways in which the towns can make the requests. For each way to make requests, find the minimum number of roads needed to meet all the requests, and print the sum of those numbers, modulo ().
Constraints
- or .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
For each way to make requests, find the minimum number of roads needed to meet all the requests, and print the sum of those numbers, modulo ().
4
2 1 -1 3
8
There are three ways to make requests, as follows:
- Choose . In this case, at least three roads - for example, - are needed to meet the requests.
- Choose . In this case, at least three roads - for example, - are needed to meet the requests.
- Choose . In this case, at least two roads - for example, - are needed to meet the requests.
Note that it is not mandatory to connect Town and Town directly.
The sum of the above numbers is .
2
2 1
1
There may be just one fixed way to make requests.
10
2 6 9 -1 6 9 -1 -1 -1 -1
527841