Statistics

Problem Statement for "AlmostEulerianGraph"

Problem Statement

In this problem we consider undirected graphs on n vertices. The vertices are numbered 0 through n-1. The graphs are simple: they do not contain self-loops, and each pair of vertices is directly connected using at most one edge.

An undirected connected graph is called Eulerian if there is a closed walk that contains each edge of the graph exactly once. (A closed walk is a sequence of consecutive edges that starts and ends in the same vertex.)

Bomboslav invented his own kind of graphs that he calls almost-Eulerian. All Eulerian graphs are also almost-Eulerian. Additionally, a graph is also almost-Eulerian if there exists a way to add or remove exactly one edge to/from it in such a way that the resulting graph becomes Eulerian. (Note that if you are adding an edge, you are not allowed to create a self-loop and you are not allowed to connect vertices that are already connected by another edge.)


An example of an almost-Eulerian graph.
After removing the selected edge, it becomes Eulerian.

.

Bomboslav is now interested in calculating the number X of different almost-Eulerian graphs on n vertices. Two graphs are considered different if there exists a pair of indices 0 <= i < j <= n-1 such that the edge (i, j) is present in exactly one of those two graphs. Compute and return the value (X modulo 1,000,000,007).

Definition

Class:
AlmostEulerianGraph
Method:
calculateGraphs
Parameters:
int
Returns:
int
Method signature:
int calculateGraphs(int n)
(be sure your method is public)

Constraints

  • n will be between 2 and 2000, inclusive.

Examples

  1. 3

    Returns: 4

    All almost-Eulerian graphs are shown in the picture below.

  2. 2

    Returns: 0

    Note that an empty graph on 2 vertices isn't Eulerian since it is disconnected.

  3. 42

    Returns: 29010676

  4. 4

    Returns: 21

  5. 5

    Returns: 418

  6. 6

    Returns: 11520

  7. 7

    Returns: 585508

  8. 8

    Returns: 53885538

  9. 9

    Returns: 271711241

  10. 10

    Returns: 608607833

  11. 20

    Returns: 917030528

  12. 43

    Returns: 173146029

  13. 57

    Returns: 931690568

  14. 100

    Returns: 416231582

  15. 256

    Returns: 40915070

  16. 525

    Returns: 577988984

  17. 789

    Returns: 282332153

  18. 999

    Returns: 88904051

  19. 1042

    Returns: 985700243

  20. 1424

    Returns: 549642530

  21. 1995

    Returns: 417308728

  22. 2000

    Returns: 634817479

  23. 1999

    Returns: 747509153

  24. 1998

    Returns: 947411569

  25. 1984

    Returns: 548269949


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: