Y
InterviewTime limit1sMemory limit1024 MB
Count the Y shapes in an undirected graph, where a root vertex has three edges to three leaves, modulo 10^9+7.
- Level
Easy3 of 10
- Topics
- Combinatorics, Graph
- Solved
- No attempts yet
Problem
Hujaro is studying graph theory and found an interesting graph. Call a simple undirected graph a Y if it has the following properties:
- It has 4 vertices and 3 edges.
- One vertex is called the root, and the other 3 vertices are called leaves.
- Each of the 3 edges connects one leaf to the root.
Hujaro thinks the properties of Y are very unusual, so he decided to count how many Ys appear in a given graph. In a simple undirected graph, the number of Ys is defined as follows:
- Choose 3 edges from the graph without regard to order. If these edges, together with the vertices they connect, form a Y, that choice counts once. The number of Ys in the graph is the number of such choices.
Given a simple undirected graph, print the number of Ys in it. The count can be very large, so print the remainder when it is divided by .
Input
The first line contains the number of vertices and the number of edges , separated by a space. (, )
Each of the next lines contains two vertices and connected by an edge, separated by a space. (, )
The graph has no multiple edges and no edges whose two endpoints are the same vertex.
Output
Print the number of Ys in the given graph, modulo .