DMOPC '21 Contest 4 P4 - Christmas Graph

View as PDF

Submit solution


Points: 17 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

There are many fun things to do in preparation for Christmas. Some decorate Christmas trees, others bake gingerbread cookies, and computer scientists like Nella build graphs. In particular, Nella starts off with a collection of N nodes. Then, for each node, she chooses one of the other nodes uniformly at random and connects the two nodes with an undirected edge. Note that it is possible for there to be more than one edge between a pair of nodes.

Nella does not want her graph to be too disconnected or it would be too much of a hassle to clean up. Therefore, as her older sibling, you should help her determine the expected number of connected components in her graph.

Constraints

2N106

Subtask 1 [5%]

2N8

Subtask 2 [35%]

2N3×103

Subtask 3 [60%]

No additional constraints.

Input Specification

The first and only line contains an integer N, the number of nodes in Nella's graph.

Output Specification

Output PQ1mod109+7, where the expected number of connected components in Nella's graph can be expressed as a fraction PQ in lowest terms, and Q1 is an integer such that QQ11(mod109+7).

Sample Input

Copy
4

Sample Output

Copy
370370374

Explanation

Out of all 81 possibilities, 78 of them form a graph with 1 connected component and 3 of them form a graph with 2 connected components. So, the expected number of connected components is 7881×1+381×2=2827.


Comments

There are no comments at the moment.