Sword Counting
Time limit5sMemory limit1024 MB
Count how many sets of six distinct vertices form a sword subtree, a fixed 6-vertex graph, in an undirected graph.
- Level
Medium7 of 10
- Topics
- Graph, Combinatorics, Implementation, Hash map
- Solved
- No attempts yet
Problem
Michael is planning to open a graph store. A graph store is a type of store which specializes in selling various graphs in different sizes and shapes. Michael has done extensive research on the market and the business seems very profitable. He has also invented a graph generator device which is able to produce any graph that he wants.
However, there is one small problem which is keeping him from starting the next booming business: Michael does not know how each graph should be priced. After weeks of reading, he found that a graph's value can be calculated based on the number of its sword subtrees. A group of six distinct vertices (let's represent them with letters A to F) form a sword subtree if the following edges exist between them (see figure):
- A is connected to B.
- B is connected to A and D.
- C is connected to D.
- D is connected to B, C, E, and F.
- E is connected to D.
- F is connected to D.
Two sword subtrees and are considered to be different if there is any edge e which exists in but does not exist in .
As a highly knowledgeable person and his business partner, your task is to help Michael count the number of sword subtrees in his generated graphs. Given an undirected graph, write a program to count the number of its sword subtrees.
Input
The first line of input will contain two integers and , (), representing the number of vertices and edges in the graph. The next lines each will contain two integers and (), the endpoints of an undirected edge. It is guaranteed that the graph described by these edges does not contain multiple edges or self loops.
Output
Output a single integer, the number of sword subtrees in the given graph.